public class SpriteBatch extends Object implements Batch
Batch
Modifier and Type | Field and Description |
---|---|
int |
maxSpritesInBatch
The maximum number of sprites rendered in one batch so far.
|
int |
renderCalls
Number of render calls since the last
begin() . |
int |
totalRenderCalls
Number of rendering calls, ever.
|
Constructor and Description |
---|
SpriteBatch()
Constructs a new SpriteBatch with a size of 1000, one buffer, and the default shader.
|
SpriteBatch(int size)
Constructs a SpriteBatch with one buffer and the default shader.
|
SpriteBatch(int size,
ShaderProgram defaultShader)
Constructs a new SpriteBatch.
|
Modifier and Type | Method and Description |
---|---|
void |
begin()
Sets up the Batch for drawing.
|
static ShaderProgram |
createDefaultShader()
Returns a new instance of the default shader used by SpriteBatch for GL2 when no shader is specified.
|
void |
disableBlending()
Disables blending for drawing sprites.
|
void |
dispose()
Releases all resources of this object.
|
void |
draw(Texture texture,
float[] spriteVertices,
int offset,
int count)
Draws a rectangle using the given vertices.
|
void |
draw(Texture texture,
float x,
float y)
Draws a rectangle with the bottom left corner at x,y having the width and height of the texture.
|
void |
draw(Texture texture,
float x,
float y,
float width,
float height)
Draws a rectangle with the bottom left corner at x,y and stretching the region to cover the given width and height.
|
void |
draw(Texture texture,
float x,
float y,
float width,
float height,
float u,
float v,
float u2,
float v2)
Draws a rectangle with the bottom left corner at x,y having the given width and height in pixels.
|
void |
draw(Texture texture,
float x,
float y,
float originX,
float originY,
float width,
float height,
float scaleX,
float scaleY,
float rotation,
int srcX,
int srcY,
int srcWidth,
int srcHeight,
boolean flipX,
boolean flipY)
Draws a rectangle with the bottom left corner at x,y having the given width and height in pixels.
|
void |
draw(Texture texture,
float x,
float y,
float width,
float height,
int srcX,
int srcY,
int srcWidth,
int srcHeight,
boolean flipX,
boolean flipY)
Draws a rectangle with the bottom left corner at x,y having the given width and height in pixels.
|
void |
draw(Texture texture,
float x,
float y,
int srcX,
int srcY,
int srcWidth,
int srcHeight)
Draws a rectangle with the bottom left corner at x,y having the given width and height in pixels.
|
void |
draw(TextureRegion region,
float x,
float y)
Draws a rectangle with the bottom left corner at x,y having the width and height of the region.
|
void |
draw(TextureRegion region,
float width,
float height,
Affine2 transform)
Draws a rectangle transformed by the given matrix.
|
void |
draw(TextureRegion region,
float x,
float y,
float width,
float height)
Draws a rectangle with the bottom left corner at x,y and stretching the region to cover the given width and height.
|
void |
draw(TextureRegion region,
float x,
float y,
float originX,
float originY,
float width,
float height,
float scaleX,
float scaleY,
float rotation)
Draws a rectangle with the bottom left corner at x,y and stretching the region to cover the given width and height.
|
void |
draw(TextureRegion region,
float x,
float y,
float originX,
float originY,
float width,
float height,
float scaleX,
float scaleY,
float rotation,
boolean clockwise)
Draws a rectangle with the texture coordinates rotated 90 degrees.
|
void |
enableBlending()
Enables blending for drawing sprites.
|
void |
end()
Finishes off rendering.
|
void |
flush()
Causes any pending sprites to be rendered, without ending the Batch.
|
int |
getBlendDstFunc() |
int |
getBlendSrcFunc() |
Color |
getColor() |
float |
getPackedColor() |
Matrix4 |
getProjectionMatrix()
Returns the current projection matrix.
|
Matrix4 |
getTransformMatrix()
Returns the current transform matrix.
|
boolean |
isBlendingEnabled() |
boolean |
isDrawing() |
void |
setBlendFunction(int srcFunc,
int dstFunc)
Sets the blending function to be used when rendering sprites.
|
void |
setColor(Color tint)
Sets the color used to tint images when they are added to the Batch.
|
void |
setColor(float color) |
void |
setColor(float r,
float g,
float b,
float a) |
void |
setProjectionMatrix(Matrix4 projection)
Sets the projection matrix to be used by this Batch.
|
void |
setShader(ShaderProgram shader)
Sets the shader to be used in a GLES 2.0 environment.
|
void |
setTransformMatrix(Matrix4 transform)
Sets the transform matrix to be used by this Batch.
|
public int renderCalls
begin()
.public int totalRenderCalls
public int maxSpritesInBatch
public SpriteBatch()
SpriteBatch(int, ShaderProgram)
public SpriteBatch(int size)
SpriteBatch(int, ShaderProgram)
public SpriteBatch(int size, ShaderProgram defaultShader)
The defaultShader specifies the shader to use. Note that the names for uniforms for this default shader are different than
the ones expect for shaders set with setShader(ShaderProgram)
. See createDefaultShader()
.
size
- The max number of sprites in a single batch. Max of 5460.defaultShader
- The default shader to use. This is not owned by the SpriteBatch and must be disposed separately.public static ShaderProgram createDefaultShader()
public void begin()
Batch
Batch.setProjectionMatrix(Matrix4)
and Batch.setTransformMatrix(Matrix4)
.public void end()
Batch
Batch.begin()
public void setColor(Color tint)
Batch
Color.WHITE
.public void setColor(float r, float g, float b, float a)
setColor
in interface Batch
Batch.setColor(Color)
public void setColor(float color)
setColor
in interface Batch
Batch.setColor(Color)
,
Color.toFloatBits()
public Color getColor()
public float getPackedColor()
getPackedColor
in interface Batch
Color.toFloatBits()
public void draw(Texture texture, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation, int srcX, int srcY, int srcWidth, int srcHeight, boolean flipX, boolean flipY)
Batch
Texture
given by srcX, srcY and srcWidth, srcHeight is used. These coordinates and sizes are given in
texels. FlipX and flipY specify whether the texture portion should be flipped horizontally or vertically.draw
in interface Batch
x
- the x-coordinate in screen spacey
- the y-coordinate in screen spaceoriginX
- the x-coordinate of the scaling and rotation origin relative to the screen space coordinatesoriginY
- the y-coordinate of the scaling and rotation origin relative to the screen space coordinateswidth
- the width in pixelsheight
- the height in pixelsscaleX
- the scale of the rectangle around originX/originY in xscaleY
- the scale of the rectangle around originX/originY in yrotation
- the angle of counter clockwise rotation of the rectangle around originX/originYsrcX
- the x-coordinate in texel spacesrcY
- the y-coordinate in texel spacesrcWidth
- the source with in texelssrcHeight
- the source height in texelsflipX
- whether to flip the sprite horizontallyflipY
- whether to flip the sprite verticallypublic void draw(Texture texture, float x, float y, float width, float height, int srcX, int srcY, int srcWidth, int srcHeight, boolean flipX, boolean flipY)
Batch
Texture
given by srcX, srcY and srcWidth, srcHeight is used. These coordinates and sizes are given in texels. FlipX
and flipY specify whether the texture portion should be flipped horizontally or vertically.draw
in interface Batch
x
- the x-coordinate in screen spacey
- the y-coordinate in screen spacewidth
- the width in pixelsheight
- the height in pixelssrcX
- the x-coordinate in texel spacesrcY
- the y-coordinate in texel spacesrcWidth
- the source with in texelssrcHeight
- the source height in texelsflipX
- whether to flip the sprite horizontallyflipY
- whether to flip the sprite verticallypublic void draw(Texture texture, float x, float y, int srcX, int srcY, int srcWidth, int srcHeight)
Batch
Texture
given by srcX, srcY and srcWidth, srcHeight are used. These coordinates and sizes are given in texels.public void draw(Texture texture, float x, float y, float width, float height, float u, float v, float u2, float v2)
Batch
public void draw(Texture texture, float x, float y)
Batch
public void draw(Texture texture, float x, float y, float width, float height)
Batch
public void draw(Texture texture, float[] spriteVertices, int offset, int count)
Batch
Batch.getColor()
from the Batch is not applied.public void draw(TextureRegion region, float x, float y)
Batch
public void draw(TextureRegion region, float x, float y, float width, float height)
Batch
public void draw(TextureRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation)
Batch
public void draw(TextureRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation, boolean clockwise)
Batch
public void draw(TextureRegion region, float width, float height, Affine2 transform)
Batch
public void flush()
Batch
public void disableBlending()
Batch
Batch.begin()
/Batch.end()
will flush the batch.disableBlending
in interface Batch
public void enableBlending()
Batch
Batch.begin()
/Batch.end()
will flush the batch.enableBlending
in interface Batch
public void setBlendFunction(int srcFunc, int dstFunc)
Batch
setBlendFunction
in interface Batch
srcFunc
- the source function, e.g. GL11.GL_SRC_ALPHA. If set to -1, Batch won't change the blending function.dstFunc
- the destination function, e.g. GL11.GL_ONE_MINUS_SRC_ALPHApublic int getBlendSrcFunc()
getBlendSrcFunc
in interface Batch
public int getBlendDstFunc()
getBlendDstFunc
in interface Batch
public void dispose()
Disposable
dispose
in interface Disposable
public Matrix4 getProjectionMatrix()
Batch
Batch.begin()
/Batch.end()
results in undefined behaviour.getProjectionMatrix
in interface Batch
public Matrix4 getTransformMatrix()
Batch
Batch.begin()
/Batch.end()
results in undefined behaviour.getTransformMatrix
in interface Batch
public void setProjectionMatrix(Matrix4 projection)
Batch
Batch.begin()
/Batch.end()
block, the
current batch is flushed to the gpu.setProjectionMatrix
in interface Batch
public void setTransformMatrix(Matrix4 transform)
Batch
Batch.begin()
/Batch.end()
block, the
current batch is flushed to the gpu.setTransformMatrix
in interface Batch
public void setShader(ShaderProgram shader)
Batch
ShaderProgram.POSITION_ATTRIBUTE
, ShaderProgram.COLOR_ATTRIBUTE
and ShaderProgram.TEXCOORD_ATTRIBUTE
which gets "0" appended to indicate the use of the first texture unit. The combined transform and projection matrx is
uploaded via a mat4 uniform called "u_projTrans". The texture sampler is passed via a uniform called "u_texture".
Call this method with a null argument to use the default shader.
This method will flush the batch before setting the new shader, you can call it in between Batch.begin()
and
Batch.end()
.
setShader
in interface Batch
shader
- the ShaderProgram
or null to use the default shader.public boolean isBlendingEnabled()
isBlendingEnabled
in interface Batch
Copyright © 2014. All rights reserved.