To draw something with a Batch one has to first call the Batch#begin() method which will setup appropriate render
states. When you are done with drawing you have to call Batch#end() which will actually draw the things you specified.
All drawing commands of the Batch operate in screen coordinates. The screen coordinate system has an x-axis pointing to the right, an y-axis pointing upwards and the origin is in the lower left corner of the screen. You can also provide your own transformation and projection matrices if you so wish.
A Batch is managed. In case the OpenGL context is lost all OpenGL resources a Batch uses internally get invalidated. A context is lost when a user switches to another application or receives an incoming call on Android. A Batch will be automatically reloaded after the OpenGL context is restored.
A Batch is a pretty heavy object so you should only ever have one in your program.
A Batch works with OpenGL ES 2.0. It will use its own custom shader to draw all provided sprites. You can set your own custom
shader via setShader(ShaderProgram).
A Batch has to be disposed if it is no longer used.
| Modifier and Type | Field and Description |
|---|---|
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int | |
| public static final int |
| Modifier and Type | Method and Description |
|---|---|
| public void | |
| public void | |
| public void | draw(Texture texture, float
the x-coordinate in screen space x, float the y-coordinate in screen space y, float the x-coordinate of the scaling and rotation origin relative to the screen space coordinates originX, float the y-coordinate of the scaling and rotation origin relative to the screen space coordinates originY, float the width in pixels width, float the height in pixels height, float the scale of the rectangle around originX/originY in x scaleX, float the scale of the rectangle around originX/originY in y scaleY, float the angle of counter clockwise rotation of the rectangle around originX/originY, in degrees rotation, int the x-coordinate in texel space srcX, int the y-coordinate in texel space srcY, int the source with in texels srcWidth, int the source height in texels srcHeight, boolean whether to flip the sprite horizontally flipX, boolean whether to flip the sprite vertically flipY)Draws a rectangle with the bottom left corner at x,y having the given width and height in pixels. |
| public void | draw(Texture texture, float
the x-coordinate in screen space x, float the y-coordinate in screen space y, float the width in pixels width, float the height in pixels height, int the x-coordinate in texel space srcX, int the y-coordinate in texel space srcY, int the source with in texels srcWidth, int the source height in texels srcHeight, boolean whether to flip the sprite horizontally flipX, boolean whether to flip the sprite vertically flipY)Draws a rectangle with the bottom left corner at x,y having the given width and height in pixels. |
| public void | draw(Texture texture, float
the x-coordinate in screen space x, float the y-coordinate in screen space y, int the x-coordinate in texel space srcX, int the y-coordinate in texel space srcY, int the source with in texels srcWidth, int the source height in texels srcHeight)Draws a rectangle with the bottom left corner at x,y having the given width and height in pixels. |
| public void | draw(Texture texture, float
the x-coordinate in screen space x, float the y-coordinate in screen space y, float the width in pixels width, float the height in pixels 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. |
| public void | |
| public void | |
| public void | |
| public 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. |
| public 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. |
| public void | draw(TextureRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float
rotation in degrees rotation)Draws a rectangle with the bottom left corner at x,y and stretching the region to cover the given width and height. |
| public void | draw(TextureRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float
rotation in degrees rotation, boolean If true, the texture coordinates are rotated 90 degrees clockwise. If false, they are rotated 90 degrees
counter clockwise. clockwise)Draws a rectangle with the texture coordinates rotated 90 degrees. |
| public void | draw(TextureRegion region, float width, float height, Affine2 transform)
Draws a rectangle transformed by the given matrix. |
| public void | |
| public void | |
| public void | |
| public int | |
| public int | |
| public int | |
| public int | |
| public Color | |
| public float | getPackedColor()
Returns: the rendering color of this Batch in vertex format (alpha compressed to 0-254) |
| public Matrix4 | |
| public ShaderProgram | |
| public Matrix4 | |
| public boolean | |
| public boolean | |
| public void | setBlendFunction(int
the source function, e.g. GL20.GL_SRC_ALPHA. If set to -1, Batch won't change the blending function. srcFunc, int the destination function, e.g. GL20.GL_ONE_MINUS_SRC_ALPHA dstFunc)Sets the blending function to be used when rendering sprites. |
| public void | setBlendFunctionSeparate(int
the source color function, e.g. GL20.GL_SRC_ALPHA. If set to -1, Batch won't change the blending
function. srcFuncColor, int the destination color function, e.g. GL20.GL_ONE_MINUS_SRC_ALPHA. dstFuncColor, int the source alpha function, e.g. GL20.GL_SRC_ALPHA. srcFuncAlpha, int the destination alpha function, e.g. GL20.GL_ONE_MINUS_SRC_ALPHA. dstFuncAlpha)Sets separate (color/alpha) blending function to be used when rendering sprites. |
| public void | |
| public void | |
| public void | setPackedColor(float packedColor)
Sets the rendering color of this Batch, expanding the alpha from 0-254 to 0-255. |
| public void | |
| public void | setShader(ShaderProgram
the shader)ShaderProgram or null to use the default shader.Sets the shader to be used in a GLES 2.0 environment. |
| public void |
| C1 | back to summary |
|---|---|
| public static final int C1 | |
| C2 | back to summary |
|---|---|
| public static final int C2 | |
| C3 | back to summary |
|---|---|
| public static final int C3 | |
| C4 | back to summary |
|---|---|
| public static final int C4 | |
| U1 | back to summary |
|---|---|
| public static final int U1 | |
| U2 | back to summary |
|---|---|
| public static final int U2 | |
| U3 | back to summary |
|---|---|
| public static final int U3 | |
| U4 | back to summary |
|---|---|
| public static final int U4 | |
| V1 | back to summary |
|---|---|
| public static final int V1 | |
| V2 | back to summary |
|---|---|
| public static final int V2 | |
| V3 | back to summary |
|---|---|
| public static final int V3 | |
| V4 | back to summary |
|---|---|
| public static final int V4 | |
| X1 | back to summary |
|---|---|
| public static final int X1 | |
| X2 | back to summary |
|---|---|
| public static final int X2 | |
| X3 | back to summary |
|---|---|
| public static final int X3 | |
| X4 | back to summary |
|---|---|
| public static final int X4 | |
| Y1 | back to summary |
|---|---|
| public static final int Y1 | |
| Y2 | back to summary |
|---|---|
| public static final int Y2 | |
| Y3 | back to summary |
|---|---|
| public static final int Y3 | |
| Y4 | back to summary |
|---|---|
| public static final int Y4 | |
| begin | back to summary |
|---|---|
| public void begin() Sets up the Batch for drawing. This will disable depth buffer writing. It enables blending and texturing. If you have more
texture units enabled than the first one you have to disable them before calling this. Uses a screen coordinate system by
default where everything is given in pixels. You can specify your own projection and modelview matrices via
| |
| disableBlending | back to summary |
|---|---|
| public void disableBlending() Disables blending for drawing sprites. Calling this within | |
| draw | back to summary |
|---|---|
| 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) Draws a rectangle with the bottom left corner at x,y having the given width and height in pixels. The rectangle is offset
by originX, originY relative to the origin. Scale specifies the scaling factor by which the rectangle should be scaled
around originX, originY. Rotation specifies the angle of counter clockwise rotation of the rectangle around originX,
originY. The portion of the
| |
| draw | back to summary |
|---|---|
| public 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. The portion of the
| |
| draw | back to summary |
|---|---|
| public 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. The portion of the
| |
| draw | back to summary |
|---|---|
| public 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. The portion of the
| |
| draw | back to summary |
|---|---|
| public 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.
| |
| draw | back to summary |
|---|---|
| public 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. | |
| draw | back to summary |
|---|---|
| public void draw(Texture texture, float[] spriteVertices, int offset, int count) Draws a rectangle using the given vertices. There must be 4 vertices, each made up of 5 elements in this order: x, y,
color, u, v. The | |
| draw | back to summary |
|---|---|
| public 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. | |
| draw | back to summary |
|---|---|
| public 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. | |
| draw | back to summary |
|---|---|
| public 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. The rectangle is offset by originX, originY relative to the origin. Scale specifies the scaling factor by which the rectangle should be scaled around originX, originY. Rotation specifies the angle of counter clockwise rotation of the rectangle around originX, originY.
| |
| draw | back to summary |
|---|---|
| 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) Draws a rectangle with the texture coordinates rotated 90 degrees. The bottom left corner at x,y and stretching the region to cover the given width and height. The rectangle is offset by originX, originY relative to the origin. Scale specifies the scaling factor by which the rectangle should be scaled around originX, originY. Rotation specifies the angle of counter clockwise rotation of the rectangle around originX, originY.
| |
| draw | back to summary |
|---|---|
| public void draw(TextureRegion region, float width, float height, Affine2 transform) Draws a rectangle transformed by the given matrix. | |
| enableBlending | back to summary |
|---|---|
| public void enableBlending() Enables blending for drawing sprites. Calling this within | |
| end | back to summary |
|---|---|
| public void end() Finishes off rendering. Enables depth writes, disables blending and texturing. Must always be called after a call to
| |
| flush | back to summary |
|---|---|
| public void flush() Causes any pending sprites to be rendered, without ending the Batch. | |
| getBlendDstFunc | back to summary |
|---|---|
| public int getBlendDstFunc() | |
| getBlendDstFuncAlpha | back to summary |
|---|---|
| public int getBlendDstFuncAlpha() | |
| getBlendSrcFunc | back to summary |
|---|---|
| public int getBlendSrcFunc() | |
| getBlendSrcFuncAlpha | back to summary |
|---|---|
| public int getBlendSrcFuncAlpha() | |
| getColor | back to summary |
|---|---|
public Color getColor()
| |
| getPackedColor | back to summary |
|---|---|
public float getPackedColor()
| |
| getProjectionMatrix | back to summary |
|---|---|
| public Matrix4 getProjectionMatrix() Returns the current projection matrix. Changing this within | |
| getShader | back to summary |
|---|---|
public ShaderProgram getShader()
| |
| getTransformMatrix | back to summary |
|---|---|
| public Matrix4 getTransformMatrix() Returns the current transform matrix. Changing this within | |
| isBlendingEnabled | back to summary |
|---|---|
public boolean isBlendingEnabled()
| |
| isDrawing | back to summary |
|---|---|
public boolean isDrawing()
| |
| setBlendFunction | back to summary |
|---|---|
| public void setBlendFunction(int srcFunc, int dstFunc) Sets the blending function to be used when rendering sprites.
| |
| setBlendFunctionSeparate | back to summary |
|---|---|
| public void setBlendFunctionSeparate(int srcFuncColor, int dstFuncColor, int srcFuncAlpha, int dstFuncAlpha) Sets separate (color/alpha) blending function to be used when rendering sprites.
| |
| setColor | back to summary |
|---|---|
| public void setColor(Color tint) Sets the color used to tint images when they are added to the Batch. Default is | |
| setColor | back to summary |
|---|---|
public void setColor(float r, float g, float b, float a)
| |
| setPackedColor | back to summary |
|---|---|
| public void setPackedColor(float packedColor) Sets the rendering color of this Batch, expanding the alpha from 0-254 to 0-255.
| |
| setProjectionMatrix | back to summary |
|---|---|
| public void setProjectionMatrix(Matrix4 projection) Sets the projection matrix to be used by this Batch. If this is called inside a | |
| setShader | back to summary |
|---|---|
| public void setShader(ShaderProgram shader) Sets the shader to be used in a GLES 2.0 environment. Vertex position attribute is called "a_position", the texture
coordinates attribute is called "a_texCoord0", the color attribute is called "a_color". See
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
| |
| setTransformMatrix | back to summary |
|---|---|
| public void setTransformMatrix(Matrix4 transform) Sets the transform matrix to be used by this Batch. | |