|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Batch
A Batch is used to draw 2D rectangles that reference a texture (region). The class will batch the drawing commands and optimize them for processing by the GPU.
To draw something with a Batch one has to first call the begin()
method which will setup appropriate render
states. When you are done with drawing you have to call 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 1.x and 2.0. In the case of a 2.0 context 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.
Field Summary | |
---|---|
static int |
C1
|
static int |
C2
|
static int |
C3
|
static int |
C4
|
static int |
U1
|
static int |
U2
|
static int |
U3
|
static int |
U4
|
static int |
V1
|
static int |
V2
|
static int |
V3
|
static int |
V4
|
static int |
X1
|
static int |
X2
|
static int |
X3
|
static int |
X4
|
static int |
Y1
|
static int |
Y2
|
static int |
Y3
|
static int |
Y4
|
Method Summary | |
---|---|
void |
begin()
Sets up the Batch for drawing. |
void |
disableBlending()
Disables blending for drawing sprites. |
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 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()
|
Matrix4 |
getProjectionMatrix()
Returns the current projection matrix. |
Matrix4 |
getTransformMatrix()
Returns the current transform matrix. |
boolean |
isBlendingEnabled()
|
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. |
Methods inherited from interface com.badlogic.gdx.utils.Disposable |
---|
dispose |
Field Detail |
---|
static final int X1
static final int Y1
static final int C1
static final int U1
static final int V1
static final int X2
static final int Y2
static final int C2
static final int U2
static final int V2
static final int X3
static final int Y3
static final int C3
static final int U3
static final int V3
static final int X4
static final int Y4
static final int C4
static final int U4
static final int V4
Method Detail |
---|
void begin()
setProjectionMatrix(Matrix4)
and setTransformMatrix(Matrix4)
.
void end()
begin()
void setColor(Color tint)
Color.WHITE
.
void setColor(float r, float g, float b, float a)
setColor(Color)
void setColor(float color)
setColor(Color)
,
Color.toFloatBits()
Color getColor()
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)
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.
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 verticallyvoid draw(Texture texture, float x, float y, float width, float height, int srcX, int srcY, int srcWidth, int srcHeight, boolean flipX, boolean flipY)
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.
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 verticallyvoid draw(Texture texture, float x, float y, int srcX, int srcY, int srcWidth, int srcHeight)
Texture
given by srcX, srcY and srcWidth, srcHeight are used. These coordinates and sizes are given in texels.
x
- the x-coordinate in screen spacey
- the y-coordinate in screen spacesrcX
- the x-coordinate in texel spacesrcY
- the y-coordinate in texel spacesrcWidth
- the source with in texelssrcHeight
- the source height in texelsvoid draw(Texture texture, float x, float y, float width, float height, float u, float v, float u2, float v2)
Texture
given by u, v and u2, v2 are used. These coordinates and sizes are given in texture size percentage. The
rectangle will have the given tint Color
.
x
- the x-coordinate in screen spacey
- the y-coordinate in screen spacewidth
- the width in pixelsheight
- the height in pixelsvoid draw(Texture texture, float x, float y)
x
- the x-coordinate in screen spacey
- the y-coordinate in screen spacevoid draw(Texture texture, float x, float y, float width, float height)
void draw(Texture texture, float[] spriteVertices, int offset, int count)
getColor()
from the Batch is not applied.
void draw(TextureRegion region, float x, float y)
void draw(TextureRegion region, float x, float y, float width, float height)
void draw(TextureRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation)
void draw(TextureRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation, boolean clockwise)
clockwise
- If true, the texture coordinates are rotated 90 degrees clockwise. If false, they are rotated 90 degrees
counter clockwise.void flush()
void disableBlending()
begin()
/end()
will flush the batch.
void enableBlending()
begin()
/end()
will flush the batch.
void setBlendFunction(int srcFunc, int dstFunc)
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_ALPHAint getBlendSrcFunc()
int getBlendDstFunc()
Matrix4 getProjectionMatrix()
begin()
/end()
results in undefined behaviour.
Matrix4 getTransformMatrix()
begin()
/end()
results in undefined behaviour.
void setProjectionMatrix(Matrix4 projection)
begin()
/end()
block, the
current batch is flushed to the gpu.
void setTransformMatrix(Matrix4 transform)
begin()
/end()
block, the
current batch is flushed to the gpu.
void setShader(ShaderProgram shader)
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 begin()
and
end()
.
shader
- the ShaderProgram
or null to use the default shader.boolean isBlendingEnabled()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |