|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch
public class PolygonSpriteBatch
A PolygonSpriteBatch is used to draw 2D polygons 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 PolygonSpriteBatch 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 PolygonSpriteBatch 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 PolygonSpriteBatch is managed. In case the OpenGL context is lost all OpenGL resources a PolygonSpriteBatch uses internally get invalidated. A context is lost when a user switches to another application or receives an incoming call on Android. A SpritPolygonSpriteBatcheBatch will be automatically reloaded after the OpenGL context is restored.
A PolygonSpriteBatch is a pretty heavy object so you should only ever have one in your program.
A PolygonSpriteBatch 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 PolygonSpriteBatch has to be disposed if it is no longer used.
Field Summary | |
---|---|
int |
maxTrianglesInBatch
The maximum number of triangles rendered in one batch so far. |
int |
renderCalls
Number of render calls since the last begin() . |
int |
totalRenderCalls
Number of rendering calls, ever. |
Constructor Summary | |
---|---|
PolygonSpriteBatch()
Constructs a new PolygonSpriteBatch with a size of 2000, the default shader, and one buffer. |
|
PolygonSpriteBatch(int size)
Constructs a PolygonSpriteBatch with the default shader and one buffer. |
|
PolygonSpriteBatch(int size,
int buffers)
Constructs a PolygonSpriteBatch with the default shader. |
|
PolygonSpriteBatch(int size,
int buffers,
ShaderProgram defaultShader)
Constructs a new PolygonSpriteBatch. |
|
PolygonSpriteBatch(int size,
ShaderProgram defaultShader)
Constructs a new PolygonSpriteBatch with one buffer. |
Method Summary | |
---|---|
void |
begin()
Sets up the PolygonSpriteBatch for drawing. |
void |
disableBlending()
Disables blending for drawing sprites. |
void |
dispose()
Disposes all resources associated with this PolygonSpriteBatch. |
void |
draw(PolygonRegion region,
float x,
float y)
Draws a polygon region with the bottom left corner at x,y having the width and height of the region. |
void |
draw(PolygonRegion region,
float x,
float y,
float width,
float height)
Draws a polygon region with the bottom left corner at x,y and stretching the region to cover the given width and height. |
void |
draw(PolygonRegion region,
float x,
float y,
float originX,
float originY,
float width,
float height,
float scaleX,
float scaleY,
float rotation)
Draws the polygon region with the bottom left corner at x,y and stretching the region to cover the given width and height. |
void |
draw(Texture texture,
float[] polygonVertices,
int verticesOffset,
int verticesCount,
short[] polygonTriangles,
int trianglesOffset,
int trianglesCount)
Draws the polygon using the given vertices and triangles. |
void |
enableBlending()
Enables blending for sprites. |
void |
end()
Finishes off rendering. |
void |
flush()
Causes any pending sprites to be rendered, without ending the PolygonSpriteBatch. |
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 PolygonSpriteBatch. |
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 PolygonSpriteBatch. |
void |
setShader(ShaderProgram shader)
|
void |
setTransformMatrix(Matrix4 transform)
Sets the transform matrix to be used by this PolygonSpriteBatch. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public int renderCalls
begin()
.
public int totalRenderCalls
public int maxTrianglesInBatch
Constructor Detail |
---|
public PolygonSpriteBatch()
PolygonSpriteBatch(int, int, ShaderProgram)
public PolygonSpriteBatch(int size)
PolygonSpriteBatch(int, int, ShaderProgram)
public PolygonSpriteBatch(int size, ShaderProgram defaultShader)
PolygonSpriteBatch(int, int, ShaderProgram)
public PolygonSpriteBatch(int size, int buffers)
PolygonSpriteBatch(int, int, ShaderProgram)
public PolygonSpriteBatch(int size, int buffers, 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 SpriteBatch.createDefaultShader()
.
size
- The max number of vertices and number of triangles in a single batch. Max of 10920.buffers
- The number of meshes to use. This is an expert function. It only makes sense with VBOs (see
Mesh.forceVBO
).defaultShader
- The default shader to use. This is not owned by the PolygonSpriteBatch and must be disposed separately.Method Detail |
---|
public void begin()
setProjectionMatrix(Matrix4)
and setTransformMatrix(Matrix4)
.
public void end()
begin()
public void setColor(Color tint)
Color.WHITE
.
public void setColor(float r, float g, float b, float a)
setColor(Color)
public void setColor(float color)
setColor(Color)
,
Color.toFloatBits()
public Color getColor()
public void draw(PolygonRegion region, float x, float y)
public void draw(PolygonRegion region, float x, float y, float width, float height)
public void draw(PolygonRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation)
public void draw(Texture texture, float[] polygonVertices, int verticesOffset, int verticesCount, short[] polygonTriangles, int trianglesOffset, int trianglesCount)
public void flush()
public void disableBlending()
begin()
/end()
will flush the batch.
public void enableBlending()
begin()
/end()
will flush the batch.
public void setBlendFunction(int srcFunc, int dstFunc)
srcFunc
- the source function, e.g. GL11.GL_SRC_ALPHA. If set to -1, PolygonSpriteBatch won't change the blending
function.dstFunc
- the destination function, e.g. GL11.GL_ONE_MINUS_SRC_ALPHApublic void dispose()
public Matrix4 getProjectionMatrix()
begin()
/end()
results in undefined behaviour.
public Matrix4 getTransformMatrix()
begin()
/end()
results in undefined behaviour.
public void setProjectionMatrix(Matrix4 projection)
begin()
/end()
block, the current batch is flushed to the gpu.
public void setTransformMatrix(Matrix4 transform)
begin()
/end()
block, the current batch is flushed to the gpu.
public void setShader(ShaderProgram shader)
SpriteBatch.setShader(ShaderProgram)
public boolean isBlendingEnabled()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |