Package gaiasky.util.gdx.g2d
Class ExtSpriteBatch
java.lang.Object
gaiasky.util.gdx.g2d.ExtSpriteBatch
- All Implemented Interfaces:
ExtBatch
-
Field Summary
Modifier and TypeFieldDescriptionstatic IntMesh.VertexDataType
Deprecated.Do not use, this field is for testing only and is likely to be removed.int
The maximum number of sprites rendered in one batch so far.int
Number of render calls since the lastbegin()
.int
Number of rendering calls, ever. -
Constructor Summary
ConstructorDescriptionConstructs a new SpriteBatch with a size of 1000, one buffer, and the default shader.ExtSpriteBatch
(int size) Constructs a SpriteBatch with one buffer and the default shader.ExtSpriteBatch
(int size, ExtShaderProgram defaultShader) Constructs a new SpriteBatch. -
Method Summary
Modifier and TypeMethodDescriptionvoid
begin()
Sets up the Batch for drawing.static ExtShaderProgram
Returns a new instance of the default shader used by SpriteBatch for GL2 when no shader is specified.void
Disables blending for drawing sprites.void
dispose()
void
draw
(com.badlogic.gdx.graphics.Texture texture, float[] spriteVertices, int offset, int count) Draws a rectangle using the given vertices.void
draw
(com.badlogic.gdx.graphics.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
(com.badlogic.gdx.graphics.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
(com.badlogic.gdx.graphics.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
(com.badlogic.gdx.graphics.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
(com.badlogic.gdx.graphics.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
(com.badlogic.gdx.graphics.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
draw
(TextureRegion region, float width, float height, com.badlogic.gdx.math.Affine2 transform) Draws a rectangle transformed by the given matrix.void
draw
(TextureView textureView, float x, float y, float width, float height, int srcX, int srcY, int srcWidth, int srcHeight, boolean flipX, boolean flipY) void
Enables blending for drawing sprites.void
end()
Finishes off rendering.void
flush()
Causes any pending sprites to be rendered, without ending the Batch.void
int
int
int
int
com.badlogic.gdx.graphics.Color
getColor()
float
com.badlogic.gdx.math.Matrix4
Returns the current projection matrix.com.badlogic.gdx.math.Matrix4
Returns the current transform matrix.boolean
boolean
void
setBlendFunction
(int srcFunc, int dstFunc) Sets the blending function to be used when rendering sprites.void
setBlendFunctionSeparate
(int srcFuncColor, int dstFuncColor, int srcFuncAlpha, int dstFuncAlpha) Sets separate (color/alpha) blending function to be used when rendering sprites.void
setColor
(float r, float g, float b, float a) void
setColor
(com.badlogic.gdx.graphics.Color tint) Sets the color used to tint images when they are added to the Batch.void
setPackedColor
(float packedColor) Sets the rendering color of this Batch, expanding the alpha from 0-254 to 0-255.void
setProjectionMatrix
(com.badlogic.gdx.math.Matrix4 projection) Sets the projection matrix to be used by this Batch.void
setShader
(ExtShaderProgram shader) Sets the shader to be used in a GLES 2.0 environment.void
setTransformMatrix
(com.badlogic.gdx.math.Matrix4 transform) Sets the transform matrix to be used by this Batch.protected void
switchTexture
(com.badlogic.gdx.graphics.Texture texture) protected void
switchTexture
(TextureView textureView)
-
Field Details
-
defaultVertexDataType
Deprecated.Do not use, this field is for testing only and is likely to be removed. Sets theIntMesh.VertexDataType
to be used when gles 3 is not available, defaults toIntMesh.VertexDataType.VertexArray
. -
renderCalls
public int renderCallsNumber of render calls since the lastbegin()
. -
totalRenderCalls
public int totalRenderCallsNumber of rendering calls, ever. Will not be reset unless set manually. -
maxSpritesInBatch
public int maxSpritesInBatchThe maximum number of sprites rendered in one batch so far.
-
-
Constructor Details
-
ExtSpriteBatch
public ExtSpriteBatch()Constructs a new SpriteBatch with a size of 1000, one buffer, and the default shader.- See Also:
-
ExtSpriteBatch
public ExtSpriteBatch(int size) Constructs a SpriteBatch with one buffer and the default shader.- See Also:
-
ExtSpriteBatch
Constructs a new SpriteBatch. Sets the projection matrix to an orthographic projection with y-axis point upwards, x-axis point to the right and the origin being in the bottom left corner of the screen. The projection will be pixel perfect with respect to the current screen resolution.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(ExtShaderProgram)
. SeecreateDefaultShader()
.- Parameters:
size
- The max number of sprites in a single batch. Max of 8191.defaultShader
- The default shader to use. This is not owned by the SpriteBatch and must be disposed separately.
-
-
Method Details
-
createDefaultShader
Returns a new instance of the default shader used by SpriteBatch for GL2 when no shader is specified. -
begin
public void begin()Description copied from interface:ExtBatch
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 viaExtBatch.setProjectionMatrix(Matrix4)
andExtBatch.setTransformMatrix(Matrix4)
. -
end
public void end()Description copied from interface:ExtBatch
Finishes off rendering. Enables depth writes, disables blending and texturing. Must always be called after a call toExtBatch.begin()
-
setColor
public void setColor(float r, float g, float b, float a) -
getColor
public com.badlogic.gdx.graphics.Color getColor()- Specified by:
getColor
in interfaceExtBatch
- Returns:
- the rendering color of this Batch. If the returned instance is manipulated,
ExtBatch.setColor(Color)
must be called afterward.
-
setColor
public void setColor(com.badlogic.gdx.graphics.Color tint) Description copied from interface:ExtBatch
Sets the color used to tint images when they are added to the Batch. Default isColor.WHITE
. -
getPackedColor
public float getPackedColor()- Specified by:
getPackedColor
in interfaceExtBatch
- Returns:
- the rendering color of this Batch in vertex format (alpha compressed to 0-254)
- See Also:
-
setPackedColor
public void setPackedColor(float packedColor) Description copied from interface:ExtBatch
Sets the rendering color of this Batch, expanding the alpha from 0-254 to 0-255.- Specified by:
setPackedColor
in interfaceExtBatch
- See Also:
-
draw
public void draw(com.badlogic.gdx.graphics.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) Description copied from interface:ExtBatch
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 theTexture
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.- Specified by:
draw
in interfaceExtBatch
- Parameters:
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 vertically
-
draw
public void draw(com.badlogic.gdx.graphics.Texture texture, float x, float y, float width, float height, int srcX, int srcY, int srcWidth, int srcHeight, boolean flipX, boolean flipY) Description copied from interface:ExtBatch
Draws a rectangle with the bottom left corner at x,y having the given width and height in pixels. The portion of theTexture
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.- Specified by:
draw
in interfaceExtBatch
- Parameters:
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 vertically
-
draw
public void draw(TextureView textureView, float x, float y, float width, float height, int srcX, int srcY, int srcWidth, int srcHeight, boolean flipX, boolean flipY) -
draw
public void draw(com.badlogic.gdx.graphics.Texture texture, float x, float y, int srcX, int srcY, int srcWidth, int srcHeight) Description copied from interface:ExtBatch
Draws a rectangle with the bottom left corner at x,y having the given width and height in pixels. The portion of theTexture
given by srcX, srcY and srcWidth, srcHeight are used. These coordinates and sizes are given in texels. -
draw
public void draw(com.badlogic.gdx.graphics.Texture texture, float x, float y, float width, float height, float u, float v, float u2, float v2) Description copied from interface:ExtBatch
Draws a rectangle with the bottom left corner at x,y having the given width and height in pixels. The portion of theTexture
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 tintColor
. -
draw
public void draw(com.badlogic.gdx.graphics.Texture texture, float x, float y) Description copied from interface:ExtBatch
Draws a rectangle with the bottom left corner at x,y having the width and height of the texture. -
draw
public void draw(com.badlogic.gdx.graphics.Texture texture, float x, float y, float width, float height) Description copied from interface:ExtBatch
Draws a rectangle with the bottom left corner at x,y and stretching the region to cover the given width and height. -
draw
public void draw(com.badlogic.gdx.graphics.Texture texture, float[] spriteVertices, int offset, int count) Description copied from interface:ExtBatch
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. TheExtBatch.getColor()
from the Batch is not applied. -
draw
Description copied from interface:ExtBatch
Draws a rectangle with the bottom left corner at x,y having the width and height of the region. -
draw
Description copied from interface:ExtBatch
Draws a rectangle with the bottom left corner at x,y and stretching the region to cover the given width and height. -
draw
public void draw(TextureRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation) Description copied from interface:ExtBatch
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
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) Description copied from interface:ExtBatch
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
public void draw(TextureRegion region, float width, float height, com.badlogic.gdx.math.Affine2 transform) Description copied from interface:ExtBatch
Draws a rectangle transformed by the given matrix. -
flush
public void flush()Description copied from interface:ExtBatch
Causes any pending sprites to be rendered, without ending the Batch. -
flushView
public void flushView() -
disableBlending
public void disableBlending()Description copied from interface:ExtBatch
Disables blending for drawing sprites. Calling this withinExtBatch.begin()
/ExtBatch.end()
will flush the batch.- Specified by:
disableBlending
in interfaceExtBatch
-
enableBlending
public void enableBlending()Description copied from interface:ExtBatch
Enables blending for drawing sprites. Calling this withinExtBatch.begin()
/ExtBatch.end()
will flush the batch.- Specified by:
enableBlending
in interfaceExtBatch
-
setBlendFunction
public void setBlendFunction(int srcFunc, int dstFunc) Description copied from interface:ExtBatch
Sets the blending function to be used when rendering sprites.- Specified by:
setBlendFunction
in interfaceExtBatch
- Parameters:
srcFunc
- the source function, e.g. GL20.GL_SRC_ALPHA. If set to -1, Batch won't change the blending function.dstFunc
- the destination function, e.g. GL20.GL_ONE_MINUS_SRC_ALPHA
-
setBlendFunctionSeparate
public void setBlendFunctionSeparate(int srcFuncColor, int dstFuncColor, int srcFuncAlpha, int dstFuncAlpha) Description copied from interface:ExtBatch
Sets separate (color/alpha) blending function to be used when rendering sprites.- Specified by:
setBlendFunctionSeparate
in interfaceExtBatch
- Parameters:
srcFuncColor
- the source color function, e.g. GL20.GL_SRC_ALPHA. If set to -1, Batch won't change the blending function.dstFuncColor
- the destination color function, e.g. GL20.GL_ONE_MINUS_SRC_ALPHA.srcFuncAlpha
- the source alpha function, e.g. GL20.GL_SRC_ALPHA.dstFuncAlpha
- the destination alpha function, e.g. GL20.GL_ONE_MINUS_SRC_ALPHA.
-
getBlendSrcFunc
public int getBlendSrcFunc()- Specified by:
getBlendSrcFunc
in interfaceExtBatch
-
getBlendDstFunc
public int getBlendDstFunc()- Specified by:
getBlendDstFunc
in interfaceExtBatch
-
getBlendSrcFuncAlpha
public int getBlendSrcFuncAlpha()- Specified by:
getBlendSrcFuncAlpha
in interfaceExtBatch
-
getBlendDstFuncAlpha
public int getBlendDstFuncAlpha()- Specified by:
getBlendDstFuncAlpha
in interfaceExtBatch
-
dispose
public void dispose() -
getProjectionMatrix
public com.badlogic.gdx.math.Matrix4 getProjectionMatrix()Description copied from interface:ExtBatch
Returns the current projection matrix. Changing this withinExtBatch.begin()
/ExtBatch.end()
results in undefined behaviour.- Specified by:
getProjectionMatrix
in interfaceExtBatch
-
setProjectionMatrix
public void setProjectionMatrix(com.badlogic.gdx.math.Matrix4 projection) Description copied from interface:ExtBatch
Sets the projection matrix to be used by this Batch. If this is called inside aExtBatch.begin()
/ExtBatch.end()
block, the current batch is flushed to the gpu.- Specified by:
setProjectionMatrix
in interfaceExtBatch
-
getTransformMatrix
public com.badlogic.gdx.math.Matrix4 getTransformMatrix()Description copied from interface:ExtBatch
Returns the current transform matrix. Changing this withinExtBatch.begin()
/ExtBatch.end()
results in undefined behaviour.- Specified by:
getTransformMatrix
in interfaceExtBatch
-
setTransformMatrix
public void setTransformMatrix(com.badlogic.gdx.math.Matrix4 transform) Description copied from interface:ExtBatch
Sets the transform matrix to be used by this Batch.- Specified by:
setTransformMatrix
in interfaceExtBatch
-
switchTexture
protected void switchTexture(com.badlogic.gdx.graphics.Texture texture) -
switchTexture
-
getShader
- Specified by:
getShader
in interfaceExtBatch
- Returns:
- the current
ExtShaderProgram
set byExtBatch.setShader(ExtShaderProgram)
or the defaultShader
-
setShader
Description copied from interface:ExtBatch
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". SeeExtShaderProgram.POSITION_ATTRIBUTE
,ExtShaderProgram.COLOR_ATTRIBUTE
andExtShaderProgram.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
ExtBatch.begin()
andExtBatch.end()
.- Specified by:
setShader
in interfaceExtBatch
- Parameters:
shader
- theExtShaderProgram
or null to use the default shader.
-
isBlendingEnabled
public boolean isBlendingEnabled()- Specified by:
isBlendingEnabled
in interfaceExtBatch
- Returns:
- true if blending for sprites is enabled
-
isDrawing
public boolean isDrawing()
-