Class SpriteBatch
- All Implemented Interfaces:
com.badlogic.gdx.graphics.g2d.Batch
,com.badlogic.gdx.utils.Disposable
A sprite batch gathers together sprites and draws them as a single mesh whenever possible. However this sprite batch is different from a classic sprite batch (from XNA or LibGDX) in that it provides a complete 2d graphics pipeline supporting both solid shapes and outlines, with texture, gradient, and scissor mask support.
This sprite batch is capable of drawing with an active texture. In that case, the shape will be drawn with a solid color. If no color has been specified, the default color is white. Outlines use the same texturing rules that solids do. There is also support for a simple, limited radius blur effect on textures.
Color gradient support is provided by the Gradient
class. All gradients
will be tinted by the current color (so the color should be reset to white
before using a gradient).
Scissor masks are supported by the Scissor
class. This is useful for
constraining shapes to an internal window. A scissor mask must be a transformed
rectangle; it cannot mask with arbitrary polygons.
Drawing only occurs when the methods flush()
or end()
are
called. Because loading vertices into a VertexBuffer
is an expensive
operation, this sprite batch attempts to minimize this as much as possible.
Even texture switches are batched. However, it is still true that using a
single texture atlas can significantly improve drawing speed.
A review of this class shows that there are a lot of redundant drawing methods.
The scene graphs only use the Mesh
methods. This goal has been to make
this class more accessible to students familiar with classic sprite batches
found in LibGDX or XNA.
It is possible to swap out the shader for this class with another one. Any
shader for this class should support SpriteMesh
as its vertex data.
If you need additional vertex information, such as normals, you should create
a new class. It should also have a uniform for the perspective matrix,
texture, and drawing type (type 0). Support for gradients and scissors occur
via a uniform block that is provides the data in the order scissor, and then
gradient. See SpriteShader.frag for more information.
This is an extremely heavy-weight class. There is rarely any need to have more
than one of these at a time. If you want to implement your own shader effects,
it is better to construct your own custom pipeline with Shader
and
VertexBuffer
.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enum
An enumeration of standard color blending options.class
Pool of text layout objects. -
Field Summary
FieldsFields inherited from interface com.badlogic.gdx.graphics.g2d.Batch
C1, C2, C3, C4, U1, U2, U3, U4, V1, V2, V3, V4, X1, X2, X3, X4, Y1, Y2, Y3, Y4
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new SpriteBatch with the default capacity and default shader.SpriteBatch
(int size) Constructs a SpriteBatch with the given size and the default shader.SpriteBatch
(int size, Shader shader) Constructs a SpriteBatch with the given capacity and shader. -
Method Summary
Modifier and TypeMethodDescriptionvoid
begin()
Starts drawing with the current perspective matrix.void
begin
(com.badlogic.gdx.graphics.Camera camera) Starts drawing with the given camera.void
clearHalfStencil
(boolean lower) Clears half of the stencil buffer.void
Clears the stencil buffer.static com.badlogic.gdx.math.Affine2
computeTransform
(float ox, float oy, float x, float y, float angle, float sx, float sy) Returns the affine transform for the given parameters.static com.badlogic.gdx.math.Affine2
computeTransform
(com.badlogic.gdx.math.Affine2 mat, float ox, float oy, float x, float y, float angle, float sx, float sy) Sets the affine transform for the given parameters.static com.badlogic.gdx.math.Affine2
computeTransform
(com.badlogic.gdx.math.Affine2 mat, com.badlogic.gdx.math.Vector2 origin, com.badlogic.gdx.math.Vector2 position, float angle, com.badlogic.gdx.math.Vector2 scale) Sets the affine transform for the given parameters.static com.badlogic.gdx.math.Affine2
computeTransform
(com.badlogic.gdx.math.Vector2 origin, com.badlogic.gdx.math.Vector2 position, float angle, com.badlogic.gdx.math.Vector2 scale) Returns the affine transform for the given parameters.void
Turns off color blending support in this sprite batchvoid
dispose()
Deletes the vertex buffers and resets all attributes.void
draw
(com.badlogic.gdx.graphics.g2d.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
(com.badlogic.gdx.graphics.g2d.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
(com.badlogic.gdx.graphics.g2d.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
(com.badlogic.gdx.graphics.g2d.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 by the given amount.void
draw
(com.badlogic.gdx.graphics.g2d.TextureRegion region, float width, float height, com.badlogic.gdx.math.Affine2 transform) Draws a rectangle transformed by the given matrix.void
draw
(com.badlogic.gdx.graphics.g2d.TextureRegion region, com.badlogic.gdx.math.Affine2 transform) Draws the the texture with the transform.void
Draws the textured polygon at the given positionvoid
draw
(com.badlogic.gdx.graphics.g2d.TextureRegion region, Poly2 poly, com.badlogic.gdx.math.Affine2 transform) Draws the given polygon of the texture with the transform.void
draw
(com.badlogic.gdx.graphics.g2d.TextureRegion region, Poly2 poly, com.badlogic.gdx.math.Vector2 offset) Draws the textured polygon at the given positionvoid
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
(com.badlogic.gdx.graphics.Texture texture, com.badlogic.gdx.math.Affine2 transform) Draws the the texture with the transform.void
Draws the textured polygon at the given positionvoid
draw
(com.badlogic.gdx.graphics.Texture texture, Poly2 poly, com.badlogic.gdx.math.Affine2 transform) Draws the given polygon of the texture with the transform.void
Draws the textured polygon at the given positionvoid
drawMesh
(SpriteMesh mesh, float x, float y, boolean tint) Draws the given mesh with the current texture and/or gradient.void
drawMesh
(SpriteMesh mesh, com.badlogic.gdx.math.Affine2 transform, boolean tint) Draws the given mesh with the current texture and/or gradient.void
drawMesh
(SpriteMesh mesh, com.badlogic.gdx.math.Vector2 offset, boolean tint) Draws the given mesh with the current texture and/or gradient.void
drawText
(TextLayout layout) Draws the formatted text on the screen.void
drawText
(TextLayout layout, float x, float y) Draws the formatted text on the screen.void
drawText
(TextLayout layout, com.badlogic.gdx.math.Affine2 transform) Draws the formatted text on the screen.void
drawText
(TextLayout layout, com.badlogic.gdx.math.Vector2 pos) Draws the formatted text on the screen.void
Draws the text on the screen.void
Draws the text on the screen.void
drawText
(String text, com.badlogic.gdx.graphics.g2d.BitmapFont font, com.badlogic.gdx.math.Affine2 transform) Draws the text on the screen.void
drawText
(String text, com.badlogic.gdx.graphics.g2d.BitmapFont font, com.badlogic.gdx.math.Vector2 pos) Draws the text on the screen.void
Sets this sprite batch to support color blendingvoid
end()
Completes the drawing pass for this sprite batch, flushing the buffer.void
fill
(float x, float y, float width, float height) Draws the given rectangle filled with the current color and texture.void
fill
(com.badlogic.gdx.math.Rectangle rect) Draws the given rectangle filled with the current color and texture.void
fill
(com.badlogic.gdx.math.Rectangle rect, float x, float y) Draws the given rectangle filled with the current color and texture.void
fill
(com.badlogic.gdx.math.Rectangle rect, com.badlogic.gdx.math.Affine2 transform) Draws the given rectangle filled with the current color and texture.void
fill
(com.badlogic.gdx.math.Rectangle rect, com.badlogic.gdx.math.Vector2 offset) Draws the given rectangle filled with the current color and texture.void
fill
(com.badlogic.gdx.math.Rectangle rect, com.badlogic.gdx.math.Vector2 origin, com.badlogic.gdx.math.Vector2 scale, float angle, com.badlogic.gdx.math.Vector2 offset) Draws the given rectangle filled with the current color and texture.void
Draws the given polygon filled with the current color and texture.void
Draws the given polygon filled with the current color and texture.void
Draws the given polygon filled with the current color and texture.void
Draws the given polygon filled with the current color and texture.void
fill
(Poly2 poly, com.badlogic.gdx.math.Vector2 origin, com.badlogic.gdx.math.Vector2 scale, float angle, com.badlogic.gdx.math.Vector2 offset) Draws the given polygon filled with the current color and texture.void
flush()
Flushes the current mesh without completing the drawing pass.int
Returns the destination blending function for the RGB componentsint
Returns the destination blending function for the alpha componentint
Returns the blending equation for this sprite batchint
Returns the source blending function for the RGB componentsint
Returns the source blending function for the alpha componentfloat
getBlur()
Returns the blur radius in pixels (0 if there is no blurring).com.badlogic.gdx.graphics.Color
getColor()
Returns the active color of this sprite batchint
Returns the current drawing command.Returns the active gradient of this sprite batchfloat
Returns the packed representation of the active colorcom.badlogic.gdx.math.Matrix4
Returns the active perspective matrix of this sprite batchReturns the active scissor mask of this sprite batchcom.badlogic.gdx.graphics.glutils.ShaderProgram
Returns the shader for this sprite batchReturns the current stencil effectcom.badlogic.gdx.math.Matrix4
Returns the active transform matrix of this sprite batchboolean
Returns whether this sprite batch supports color blendingboolean
Returns true if this sprite batch is actively drawing.void
outline
(float x, float y, float width, float height) Outlines the given rectangle with the current color and texture.void
outline
(com.badlogic.gdx.math.Rectangle rect) Outlines the given rectangle with the current color and texture.void
outline
(com.badlogic.gdx.math.Rectangle rect, float x, float y) Outlines the given rectangle with the current color and texture.void
outline
(com.badlogic.gdx.math.Rectangle rect, com.badlogic.gdx.math.Affine2 transform) Outlines the given rectangle with the current color and texture.void
outline
(com.badlogic.gdx.math.Rectangle rect, com.badlogic.gdx.math.Vector2 offset) Outlines the given rectangle with the current color and texture.void
outline
(com.badlogic.gdx.math.Rectangle rect, com.badlogic.gdx.math.Vector2 origin, com.badlogic.gdx.math.Vector2 scale, float angle, com.badlogic.gdx.math.Vector2 offset) Outlines the given rectangle with the current color and texture.void
Outlines the given path with the current color and texture.void
Outlines the given path with the current color and texture.void
Outlines the given path with the current color and texture.void
Outlines the given path with the current color and texture.void
outline
(Path2 path, com.badlogic.gdx.math.Vector2 origin, com.badlogic.gdx.math.Vector2 scale, float angle, com.badlogic.gdx.math.Vector2 offset) Outlines the given path with the current color and texture.void
setBlendDstFunc
(int func) Sets the blending function for the destination colorvoid
setBlendDstFunc
(int rgb, int alpha) Sets the blending functions for the destination colorvoid
setBlendEquation
(int equation) Sets the blending equation for this sprite batchvoid
setBlendFunction
(int srcFactor, int dstFactor) Sets the blending function for this sprite batchvoid
setBlendFunctionSeparate
(int srcFactorColor, int dstFactorColor, int srcFactorAlpha, int dstFactorAlpha) Sets the blending function for this sprite batchvoid
Sets the blending mode for this sprite batchvoid
setBlendSrcFunc
(int func) Sets the blending function for the source colorvoid
setBlendSrcFunc
(int rgb, int alpha) Sets the blending functions for the source colorvoid
setBlur
(float radius) Sets the blur radius in pixels (0 if there is no blurring).void
setColor
(float r, float g, float b, float a) Sets the active color of this sprite batchvoid
setColor
(com.badlogic.gdx.graphics.Color tint) Sets the active color of this sprite batchvoid
setCommand
(int command) Sets the current drawing command.void
setGradient
(Gradient gradient) Sets the active gradient of this sprite batchvoid
setPackedColor
(float packed) Sets the active color of this sprite batchvoid
setProjectionMatrix
(com.badlogic.gdx.math.Matrix4 projection) Sets the active perspective matrix of this sprite batchvoid
setScissor
(Scissor scissor) Sets the active scissor mask of this sprite batchvoid
setShader
(com.badlogic.gdx.graphics.glutils.ShaderProgram shader) Sets the shader for this sprite batchvoid
Sets the shader for this sprite batchvoid
setStencilEffect
(Stencil.Effect effect) Sets the current stencil effectvoid
setTexture
(com.badlogic.gdx.graphics.Texture texture) Sets the active texture of this sprite batchvoid
setTextureRegion
(com.badlogic.gdx.graphics.g2d.TextureRegion region) Sets the active texture region of this sprite batchvoid
setTransformMatrix
(com.badlogic.gdx.math.Matrix4 transform) Sets the active transform matrix of this sprite batch
-
Field Details
-
DEFAULT_CAPACITY
public static final int DEFAULT_CAPACITYThe default vertex capacity- See Also:
-
-
Constructor Details
-
SpriteBatch
public SpriteBatch()Constructs a new SpriteBatch with the default capacity and default shader. -
SpriteBatch
public SpriteBatch(int size) Constructs a SpriteBatch with the given size and the default shader.- Parameters:
size
- The vertex capacity- See Also:
-
SpriteBatch
Constructs a SpriteBatch with the given capacity and shader.The shader is not owned by this sprite batch and must be disposed of separately. If extended is false, the shader it assumed to be a traditional sprite shader with a stride of 5 floats (position, color, and texture coords). If extended it true, it has a stride of 7 in order to include gradient coordinates.
- Parameters:
size
- The vertex capacityshader
- The shader to use
-
-
Method Details
-
dispose
public void dispose()Deletes the vertex buffers and resets all attributes.Unlike CUGL, a disposed LibGDX object is not designed to be reused. This is designed to get rid of the heavy-weight OpenGL classes.
- Specified by:
dispose
in interfacecom.badlogic.gdx.utils.Disposable
-
isDrawing
public boolean isDrawing()Returns true if this sprite batch is actively drawing.Some changes cannot be made while the sprite batch is drawing.
- Specified by:
isDrawing
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- Returns:
- true if this sprite batch is actively drawing.
-
setShader
Sets the shader for this sprite batchThis value may NOT be changed during a drawing pass. The shader must be attribute compatible with the original shader.
- Parameters:
shader
- The active shader for this sprite batch
-
setShader
public void setShader(com.badlogic.gdx.graphics.glutils.ShaderProgram shader) Sets the shader for this sprite batchThis value may NOT be changed during a drawing pass.
- Specified by:
setShader
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- Parameters:
shader
- The active shader for this sprite batch
-
getShader
public com.badlogic.gdx.graphics.glutils.ShaderProgram getShader()Returns the shader for this sprite batchThis value may NOT be changed during a drawing pass.
- Specified by:
getShader
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- Returns:
- the shader for this sprite batch
-
setColor
public void setColor(com.badlogic.gdx.graphics.Color tint) Sets the active color of this sprite batchAll subsequent shapes and outlines drawn by this sprite batch will be tinted by this color. This color is white by default.
- Specified by:
setColor
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- Parameters:
tint
- The active color for this sprite batch
-
setColor
public void setColor(float r, float g, float b, float a) Sets the active color of this sprite batchAll subsequent shapes and outlines drawn by this sprite batch will be tinted by this color. This color is white by default.
- Specified by:
setColor
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- Parameters:
r
- The red value of the active colorg
- The green value of the active colorb
- The blue value of the active colora
- The alpha value of the active color
-
getColor
public com.badlogic.gdx.graphics.Color getColor()Returns the active color of this sprite batchAll subsequent shapes and outlines drawn by this sprite batch will be tinted by this color. This color is white by default.
- Specified by:
getColor
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- Returns:
- the active color for this sprite batch
-
setPackedColor
public void setPackedColor(float packed) Sets the active color of this sprite batchAll subsequent shapes and outlines drawn by this sprite batch will be tinted by this color. This color is white by default.
- Specified by:
setPackedColor
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- Parameters:
packed
- The packed encoding of the active color
-
getPackedColor
public float getPackedColor()Returns the packed representation of the active colorThis packed representation allows us to represent the color as a single float value.
- Specified by:
getPackedColor
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- Returns:
- the packed representation of the active color
-
isBlendingEnabled
public boolean isBlendingEnabled()Returns whether this sprite batch supports color blending- Specified by:
isBlendingEnabled
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- Returns:
- whether this sprite batch supports color blending
-
enableBlending
public void enableBlending()Sets this sprite batch to support color blending- Specified by:
enableBlending
in interfacecom.badlogic.gdx.graphics.g2d.Batch
-
disableBlending
public void disableBlending()Turns off color blending support in this sprite batch- Specified by:
disableBlending
in interfacecom.badlogic.gdx.graphics.g2d.Batch
-
setBlendMode
Sets the blending mode for this sprite batchThis method uses our
SpriteBatch.BlendMode
enum to set one of the predefined blending modes. Most of the time, this should be all that you need.- Parameters:
mode
- The color blending mode
-
setBlendFunction
public void setBlendFunction(int srcFactor, int dstFactor) Sets the blending function for this sprite batchThe enums are the standard ones supported by OpenGL. See
https://www.opengl.org/sdk/docs/man/html/glBlendFunc.xhtml
However, this setter does not do any error checking to verify that the enums are valid. By default, srcFactor is GL_SRC_ALPHA while dstFactor is GL_ONE_MINUS_SRC_ALPHA. This corresponds to non-premultiplied alpha blending.- Specified by:
setBlendFunction
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- Parameters:
srcFactor
- Specifies how the source color is blendeddstFactor
- Specifies how the destination color is blended
-
setBlendFunctionSeparate
public void setBlendFunctionSeparate(int srcFactorColor, int dstFactorColor, int srcFactorAlpha, int dstFactorAlpha) Sets the blending function for this sprite batchThe enums are the standard ones supported by OpenGL. See
https://www.opengl.org/sdk/docs/man/html/glBlendFunc.xhtml
However, this setter does not do any error checking to verify that the enums are valid. By default, srcFactor is GL_SRC_ALPHA while dstFactor is GL_ONE_MINUS_SRC_ALPHA. This corresponds to non-premultiplied alpha blending.This method is different from
setBlendFunction(int,int)
in that it allows for separate blend functions for the color and alpha components.- Specified by:
setBlendFunctionSeparate
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- Parameters:
srcFactorColor
- Specifies how the source color is blendeddstFactorColor
- Specifies how the destination color is blendedsrcFactorAlpha
- Specifies how the source alpha is blendeddstFactorAlpha
- Specifies how the destination alpha is blended
-
setBlendSrcFunc
public void setBlendSrcFunc(int func) Sets the blending function for the source colorThe enums are the standard ones supported by OpenGL. See
https://www.opengl.org/sdk/docs/man/html/glBlendFunc.xhtml
However, this setter does not do any error checking to verify that the enums are valid.By default this value is GL_SRC_ALPHA, as sprite batches do not use premultiplied alpha.
- Parameters:
func
- Specifies how the source color is blended
-
setBlendSrcFunc
public void setBlendSrcFunc(int rgb, int alpha) Sets the blending functions for the source colorThe enums are the standard ones supported by OpenGL. See
https://www.opengl.org/sdk/docs/man/html/glBlendFunc.xhtml
This version of the function allows you to specify different blending fuctions for the RGB and alpha components of the source color. This setter does not do any error checking to verify that the enums are valid.By default both values are GL_SRC_ALPHA, as sprite batches do not use premultiplied alpha.
- Parameters:
rgb
- The blend function for the source RGB componentsalpha
- The blend function for the source alpha component
-
getBlendSrcFunc
public int getBlendSrcFunc()Returns the source blending function for the RGB componentsBy default this value is GL_SRC_ALPHA, as sprite batches do not use premultiplied alpha. For other options, see
https://www.opengl.org/sdk/docs/man/html/glBlendFunc.xhtml
- Specified by:
getBlendSrcFunc
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- Returns:
- the source blending function for the RGB components
-
getBlendSrcFuncAlpha
public int getBlendSrcFuncAlpha()Returns the source blending function for the alpha componentBy default this value is GL_SRC_ALPHA, as sprite batches do not use premultiplied alpha. For other options, see
https://www.opengl.org/sdk/docs/man/html/glBlendFunc.xhtml
- Specified by:
getBlendSrcFuncAlpha
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- Returns:
- the source blending function for the alpha component
-
setBlendDstFunc
public void setBlendDstFunc(int func) Sets the blending function for the destination colorThe enums are the standard ones supported by OpenGL. See
https://www.opengl.org/sdk/docs/man/html/glBlendFunc.xhtml
However, this setter does not do any error checking to verify that the enums are valid.By default this value is GL_ONE_MINUS_SRC_ALPHA, as sprite batches do not use premultiplied alpha.
- Parameters:
func
- Specifies how the source color is blended
-
setBlendDstFunc
public void setBlendDstFunc(int rgb, int alpha) Sets the blending functions for the destination colorThe enums are the standard ones supported by OpenGL. See
https://www.opengl.org/sdk/docs/man/html/glBlendFunc.xhtml
This version of the function allows you to specify different blending fuctions for the RGB and alpha components of the destiniation color. This setter does not do any error checking to verify that the enums are valid.By default both values are GL_ONE_MINUS_SRC_ALPHA, as sprite batches do not use premultiplied alpha.
- Parameters:
rgb
- The blend function for the source RGB componentsalpha
- The blend function for the source alpha component
-
getBlendDstFunc
public int getBlendDstFunc()Returns the destination blending function for the RGB componentsBy default this value is GL_ONE_MINUS_SRC_ALPHA, as sprite batches do not use premultiplied alpha. For other options, see
https://www.opengl.org/sdk/docs/man/html/glBlendFunc.xhtml
- Specified by:
getBlendDstFunc
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- Returns:
- the destination blending function for the RGB components
-
getBlendDstFuncAlpha
public int getBlendDstFuncAlpha()Returns the destination blending function for the alpha componentBy default this value is GL_ONE_MINUS_SRC_ALPHA, as sprite batches do not use premultiplied alpha. For other options, see
https://www.opengl.org/sdk/docs/man/html/glBlendFunc.xhtml
- Specified by:
getBlendDstFuncAlpha
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- Returns:
- the destination blending function for the alpha component
-
setBlendEquation
public void setBlendEquation(int equation) Sets the blending equation for this sprite batchThe enum must be a standard ones supported by OpenGL. See
https://www.opengl.org/sdk/docs/man/html/glBlendEquation.xhtml
However, this setter does not do any error checking to verify that the input is valid. By default, the equation is GL_FUNC_ADD.- Parameters:
equation
- Specifies how source and destination colors are combined
-
getBlendEquation
public int getBlendEquation()Returns the blending equation for this sprite batchBy default this value is GL_FUNC_ADD. For other options, see
https://www.opengl.org/sdk/docs/man/html/glBlendEquation.xhtml
- Returns:
- the blending equation for this sprite batch
-
setBlur
public void setBlur(float radius) Sets the blur radius in pixels (0 if there is no blurring).This sprite batch supports a simple Gaussian blur. The blur samples at 5 points along each axis. The values are essentially at the radius, half-radius, and center. Because of the limited sampling, large radii will start to produce a pixellation effect. But it can produce acceptable blur effects with little cost to performance. It is especially ideal for font-blur effects on font atlases.
When applying a blur to a text, make sure that the source font has padding set to at least the blur radius. Otherwise, the blur will bleed into other glyphs.
Setting this value to 0 will disable texture blurring. This value is 0 by default.
- Parameters:
radius
- The blur radius in pixels
-
getBlur
public float getBlur()Returns the blur radius in pixels (0 if there is no blurring).This sprite batch supports a simple Gaussian blur. The blur samples at 5 points along each axis. The values are essentially at the radius, half-radius, and center. Because of the limited sampling, large radii will start to produce a pixellation effect. But it can produce acceptable blur effects with little cost to performance. It is especially ideal for font-blur effects on font atlases.
When applying a blur to a text, make sure that the source font has padding set to at least the blur radius. Otherwise, the blur will bleed into other glyphs.
Setting this value to 0 will disable texture blurring. This value is 0 by default.
- Returns:
- the blur step in pixels (0 if there is no blurring).
-
getProjectionMatrix
public com.badlogic.gdx.math.Matrix4 getProjectionMatrix()Returns the active perspective matrix of this sprite batchThe perspective matrix is the combined modelview-projection from the camera. By default, this is the identity matrix.
This method returns a copy of the matrix. Changes to this object have no effect on the sprite batch.
- Specified by:
getProjectionMatrix
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- Returns:
- the active perspective matrix of this sprite batch
-
getTransformMatrix
public com.badlogic.gdx.math.Matrix4 getTransformMatrix()Returns the active transform matrix of this sprite batchThe transform matrix is a unified transform applied to all vertices in the sprite batch. By default, this is the identity matrix.
This method returns a copy of the matrix. Changes to this object have no effect on the sprite batch.
- Specified by:
getTransformMatrix
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- Returns:
- the active perspective matrix of this sprite batch
-
setProjectionMatrix
public void setProjectionMatrix(com.badlogic.gdx.math.Matrix4 projection) Sets the active perspective matrix of this sprite batchThe perspective matrix is the combined modelview-projection from the camera. By default, this is the identity matrix.
This method acquires a copy of the matrix. Changes to the original matrix after calling this method have no effect.
- Specified by:
setProjectionMatrix
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- Parameters:
projection
- The active projection matrix for this sprite batch
-
setTransformMatrix
public void setTransformMatrix(com.badlogic.gdx.math.Matrix4 transform) Sets the active transform matrix of this sprite batchThe transform matrix is a unified transform applied to all vertices in the sprite batch. By default, this is the identity matrix.
This method acquires a copy of the matrix. Changes to the original matrix after calling this method have no effect.
- Specified by:
setTransformMatrix
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- Parameters:
transform
- the active transform matrix of this sprite batch
-
getGradient
Returns the active gradient of this sprite batchGradients may be used in the place of (and together with) colors.
By default, the gradient will not be used (as it is slower than solid colors).
All gradients are tinted by the active color. Unless you explicitly want this tinting, you should set the active color to white before drawing with an active gradient.
This method returns a copy of the internal gradient. Changes to this object have no effect on the sprite batch.
- Returns:
- The active gradient for this sprite batch
-
setGradient
Sets the active gradient of this sprite batchGradients may be used in the place of (and together with) colors.
If this value is null, then no gradient is active. In that case, the color vertex attribute will be interpretted as normal (e.g. a traditional color vector). This value is null by default.
All gradients are tinted by the active color. Unless you explicitly want this tinting, you should set the active color to white before drawing with an active gradient.
This method acquires a copy of the gradient. Changes to the original gradient after calling this method have no effect.
- Parameters:
gradient
- The active gradient for this sprite batch
-
getScissor
Returns the active scissor mask of this sprite batchScissor masks may be combined with all types of drawing (colors, textures, and gradients).
If this value is null, then no scissor mask is active. This value is null by default.
This method returns a copy of the internal scissor. Changes to this object have no effect on the sprite batch.
- Returns:
- The active scissor mask for this sprite batch
-
setScissor
Sets the active scissor mask of this sprite batchScissor masks may be combined with all types of drawing (colors, textures, and gradients).
If this value is null, then no scissor mask is active. This value is null by default.
This method acquires a copy of the scissor. Changes to the original scissor mask after calling this method have no effect.
- Parameters:
scissor
- The active scissor mask for this sprite batch
-
setCommand
public void setCommand(int command) Sets the current drawing command.The value must be one of GL_TRIANGLES or GL_LINES. Changing this value during a drawing pass will flush the buffer.
- Parameters:
command
- The OpenGL drawing command
-
getCommand
public int getCommand()Returns the current drawing command.The value must be one of GL_TRIANGLES or GL_LINES. Changing this value during a drawing pass will flush the buffer.
- Returns:
- the current drawing command.
-
setTexture
public void setTexture(com.badlogic.gdx.graphics.Texture texture) Sets the active texture of this sprite batchAll subsequent shapes and outlines drawn by this sprite batch will use this texture. If the value is null, all shapes and outlines will be draw with a solid color instead. This value is null by default.
Changing this value will cause the sprite batch to flush. This is an important argument for using texture atlases.
- Parameters:
texture
- The active texture for this sprite batch
-
setTextureRegion
public void setTextureRegion(com.badlogic.gdx.graphics.g2d.TextureRegion region) Sets the active texture region of this sprite batchAll subsequent shapes and outlines drawn by this sprite batch will use this texture region. If the value is null, all shapes and outlines will be draw with a solid color instead. This value is null by default.
Changing the texture will cause the sprite batch to flush. However, using a different region for the same texture will not cause a pipeline flush. This is an important argument for using texture atlases.
- Parameters:
region
- The active texture region for this sprite batch
-
setStencilEffect
Sets the current stencil effectStencil effects can be used to restrict the drawing region and are generally used to speed up the processing of non-convex shapes. See
Stencil
for the list of supported effects, as well as a discussion of how the two halves of the stencil buffer work.This value should be set to
Stencil.Effect.NATIVE
(the default) if you wish to directly manipulate the OpenGL stencil. This is sometimes necessary for more complex effects.- Parameters:
effect
- The current stencil effect
-
getStencilEffect
Returns the current stencil effectStencil effects can be used to restrict the drawing region and are generally used to speed up the processing of non-convex shapes. See
Stencil
for the list of supported effects, as well as a discussion of how the two halves of the stencil buffer work.This value should be set to
Stencil.Effect.NATIVE
(the default) if you wish to directly manipulate the OpenGL stencil. This is sometimes necessary for more complex effects.- Returns:
- the current stencil effect
-
clearStencil
public void clearStencil()Clears the stencil buffer.This method clears both halves of the stencil buffer: both upper and lower. See
Stencil
for a discussion of how the two halves of the stencil buffer work. -
clearHalfStencil
public void clearHalfStencil(boolean lower) Clears half of the stencil buffer.This method clears only one of the two halves of the stencil buffer. See
Stencil
for a discussion of how the two halves of the stencil buffer work.- Parameters:
lower
- Whether to clear the lower stencil buffer
-
computeTransform
public static com.badlogic.gdx.math.Affine2 computeTransform(com.badlogic.gdx.math.Vector2 origin, com.badlogic.gdx.math.Vector2 position, float angle, com.badlogic.gdx.math.Vector2 scale) Returns the affine transform for the given parameters.One of the reasons for the proliferation of methods in the LibGDX Batch class is all of the ways that we can transform the image. To simplify this, most of our new methods simply use an
Affine2
transform. However, computing transforms can be tricky. This method provides an easy way to generate them.- Parameters:
origin
- The of texture origin (in pixels)position
- The texture positionangle
- The rotation angle (in degrees) about the origin.scale
- The scaling factor- Returns:
- the affine transform for the given parameters.
-
computeTransform
public static com.badlogic.gdx.math.Affine2 computeTransform(com.badlogic.gdx.math.Affine2 mat, com.badlogic.gdx.math.Vector2 origin, com.badlogic.gdx.math.Vector2 position, float angle, com.badlogic.gdx.math.Vector2 scale) Sets the affine transform for the given parameters.One of the reasons for the proliferation of methods in the LibGDX Batch class is all of the ways that we can transform the image. To simplify this, most of our new methods simply use an
Affine2
transform. However, computing transforms can be tricky. This method provides an easy way to generate them.- Parameters:
mat
- The object to store the resultsorigin
- The of texture origin (in pixels)position
- The texture positionangle
- The rotation angle (in degrees) about the origin.scale
- The scaling factor- Returns:
- the provided affine transform
-
computeTransform
public static com.badlogic.gdx.math.Affine2 computeTransform(float ox, float oy, float x, float y, float angle, float sx, float sy) Returns the affine transform for the given parameters.One of the reasons for the proliferation of methods in the LibGDX Batch class is all of the ways that we can transform the image. To simplify this, most of our new methods simply use an
Affine2
transform. However, computing transforms can be tricky. This method provides an easy way to generate them.- Parameters:
ox
- The x-coordinate of texture origin (in pixels)oy
- The y-coordinate of texture origin (in pixels)x
- The x-coordinate of the texturey
- The y-coordinate of the textureangle
- The rotation angle (in degrees) about the origin.sx
- The x-axis scaling factorsy
- The y-axis scaling factor- Returns:
- the affine transform for the given parameters.
-
computeTransform
public static com.badlogic.gdx.math.Affine2 computeTransform(com.badlogic.gdx.math.Affine2 mat, float ox, float oy, float x, float y, float angle, float sx, float sy) Sets the affine transform for the given parameters.One of the reasons for the proliferation of methods in the LibGDX Batch class is all of the ways that we can transform the image. To simplify this, most of our new methods simply use an
Affine2
transform. However, computing transforms can be tricky. This method provides an easy way to generate them.- Parameters:
mat
- The object to store the resultsox
- The x-coordinate of texture origin (in pixels)oy
- The y-coordinate of texture origin (in pixels)x
- The x-coordinate of the texturey
- The y-coordinate of the textureangle
- The rotation angle (in degrees) about the origin.sx
- The x-axis scaling factorsy
- The y-axis scaling factor- Returns:
- the provided affine transform
-
begin
public void begin()Starts drawing with the current perspective matrix.This call will disable depth buffer writing. It enables blending and texturing. You must call
end()
to complete drawing.Calling this method will reset the vertex and OpenGL call counters to 0.
- Specified by:
begin
in interfacecom.badlogic.gdx.graphics.g2d.Batch
-
begin
public void begin(com.badlogic.gdx.graphics.Camera camera) Starts drawing with the given camera.The camera will be used to set the perspective matrix. This call will disable depth buffer writing. It enables blending and texturing. You must call
end()
to complete drawing.Calling this method will reset the vertex and OpenGL call counters to 0.
- Parameters:
camera
- The camera for the drawing perspective
-
end
public void end()Completes the drawing pass for this sprite batch, flushing the buffer.This method will unbind the associated shader. It must always be called after a call to
begin()
.- Specified by:
end
in interfacecom.badlogic.gdx.graphics.g2d.Batch
-
flush
public void flush()Flushes the current mesh without completing the drawing pass.This method is called whenever you change any attribute other than color mid-pass. It prevents the attribute change from retoactively affecting previuosly drawn shapes.
If you play to apply any OpenGL functionality not directly supported by this sprite batch (e.g stencils), you MUST call this method first before applying your effects. In addition, you should call this again before restoring the OpenGL state.
- Specified by:
flush
in interfacecom.badlogic.gdx.graphics.g2d.Batch
-
fill
public void fill(com.badlogic.gdx.math.Rectangle rect) Draws the given rectangle filled with the current color and texture.The texture will fill the entire rectangle with texture coordinate (0,1) at the bottom left corner identified by rect,origin. To draw only part of a texture, use a subtexture to fill the rectangle with the region [minS,maxS]x[min,maxT]. Alternatively, you can use a
Poly2
for more fine-tuned control.- Parameters:
rect
- The rectangle to draw
-
fill
public void fill(float x, float y, float width, float height) Draws the given rectangle filled with the current color and texture.The texture will fill the entire rectangle with texture coordinate (0,1) at the bottom left corner identified by rect,origin. To draw only part of a texture, use a subtexture to fill the rectangle with the region [minS,maxS]x[min,maxT]. Alternatively, you can use a
Poly2
for more fine-tuned control.- Parameters:
x
- The x-coordinate of the lower left cornery
- The y-coordinate of the lower left cornerwidth
- The width of the rectangleheight
- The height of the rectangle
-
fill
public void fill(com.badlogic.gdx.math.Rectangle rect, com.badlogic.gdx.math.Vector2 offset) Draws the given rectangle filled with the current color and texture.The texture will fill the entire rectangle with texture coordinate (0,1) at the bottom left corner identified by rect,origin. To draw only part of a texture, use a subtexture to fill the rectangle with the region [minS,maxS]x[min,maxT]. Alternatively, you can use a
Poly2
for more fine-tuned control.- Parameters:
rect
- The rectangle to drawoffset
- The rectangle offset
-
fill
public void fill(com.badlogic.gdx.math.Rectangle rect, float x, float y) Draws the given rectangle filled with the current color and texture.The texture will fill the entire rectangle with texture coordinate (0,1) at the bottom left corner identified by rect,origin. To draw only part of a texture, use a subtexture to fill the rectangle with the region [minS,maxS]x[min,maxT]. Alternatively, you can use a
Poly2
for more fine-tuned control.- Parameters:
rect
- The rectangle to drawx
- The rectangle x offsety
- The rectangle y offset
-
fill
public void fill(com.badlogic.gdx.math.Rectangle rect, com.badlogic.gdx.math.Vector2 origin, com.badlogic.gdx.math.Vector2 scale, float angle, com.badlogic.gdx.math.Vector2 offset) Draws the given rectangle filled with the current color and texture.The rectangle will be scaled first, then rotated, and finally offset by the given position. Rotation is measured in radians and is counter clockwise from the x-axis. Rotation will be about the provided origin, which is specified relative to the origin of the rectangle (not world coordinates). So to spin about the center, the origin should be width/2, height/2 of the rectangle.
The texture will fill the entire rectangle before being transformed. Texture coordinate (0,1) will at the bottom left corner identified by rect,origin. To draw only part of a texture, use a subtexture to fill the rectangle with the region [minS,maxS]x[min,maxT]. Alternatively, you can use a
Poly2
for more fine-tuned control.- Parameters:
rect
- The rectangle to draworigin
- The rotational offset in the rectanglescale
- The amount to scale the rectangleangle
- The amount to rotate the rectangleoffset
- The rectangle offset in world coordinates
-
fill
public void fill(com.badlogic.gdx.math.Rectangle rect, com.badlogic.gdx.math.Affine2 transform) Draws the given rectangle filled with the current color and texture.The rectangle will transformed by the given matrix. The transform will be applied to the origin of the rectangle.
The texture will fill the entire rectangle with texture coordinate (0,1) at the bottom left corner identified by rect,origin. To draw only part of a texture, use a subtexture to fill the rectangle with the region [minS,maxS]x[min,maxT]. Alternatively, you can use a
Poly2
for more fine-tuned control.- Parameters:
rect
- The rectangle to drawtransform
- The coordinate transform
-
fill
Draws the given polygon filled with the current color and texture.The polygon tesselation will be determined by the indices in poly. If the polygon has not been triangulated it may not draw properly.
The vertex coordinates will be determined by polygon vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply drawing the texture.
One way to think of the polygon is as a "cookie cutter". Treat the polygon coordinates as pixel coordinates in the texture file, and use that to determine how the texture fills the polygon. This may make the polygon larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this.
- Parameters:
poly
- The polygon to draw
-
fill
Draws the given polygon filled with the current color and texture.The polygon will be offset by the given position.
The polygon tesselation will be determined by the indices in poly. If the polygon has not been triangulated it may not draw properly.
The vertex coordinates will be determined by polygon vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply drawing the texture.
One way to think of the polygon is as a "cookie cutter". Treat the polygon coordinates as pixel coordinates in the texture file, and use that to determine how the texture fills the polygon. This may make the polygon larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this.
- Parameters:
poly
- The polygon to drawoffset
- The polygon offset
-
fill
Draws the given polygon filled with the current color and texture.The polygon will be offset by the given position.
The polygon tesselation will be determined by the indices in poly. If the polygon has not been triangulated it may not draw properly.
The vertex coordinates will be determined by polygon vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply drawing the texture.
One way to think of the polygon is as a "cookie cutter". Treat the polygon coordinates as pixel coordinates in the texture file, and use that to determine how the texture fills the polygon. This may make the polygon larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this. If depth testing is on, all vertices will use the current sprite batch depth.
- Parameters:
poly
- The polygon to drawx
- The x offsety
- The y offset
-
fill
public void fill(Poly2 poly, com.badlogic.gdx.math.Vector2 origin, com.badlogic.gdx.math.Vector2 scale, float angle, com.badlogic.gdx.math.Vector2 offset) Draws the given polygon filled with the current color and texture.The polygon will be scaled first, then rotated, and finally offset by the given position. Rotation is measured in radians and is counter clockwise from the x-axis. Rotation will be about the provided origin, which is specified relative to the origin of the polygon (not world coordinates). Hence this origin is essentially the pixel coordinate of the texture (see below) to assign as the rotational center.
The polygon tesselation will be determined by the indices in poly. If the polygon has not been triangulated it may not draw properly.
The vertex coordinates will be determined by polygon vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply drawing the texture.
One way to think of the polygon is as a "cookie cutter". Treat the polygon coordinates as pixel coordinates in the texture file, and use that to determine how the texture fills the polygon. This may make the polygon larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this.
- Parameters:
poly
- The polygon to draworigin
- The image origin in pixel spacescale
- The amount to scale the polygonangle
- The amount to rotate the polygonoffset
- The polygon offset in world coordinates
-
fill
Draws the given polygon filled with the current color and texture.The polygon will transformed by the given matrix. The transform will be applied to the origin of the path (not world coordinates). Hence this origin is essentially the pixel coordinate of the texture (see below) to assign as the origin of this transform.
The polygon tesselation will be determined by the indices in poly. If the polygon has not been triangulated it may not draw properly.
The vertex coordinates will be determined by polygon vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply drawing the texture.
One way to think of the polygon is as a "cookie cutter". Treat the polygon coordinates as pixel coordinates in the texture file, and use that to determine how the texture fills the polygon. This may make the polygon larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this.
- Parameters:
poly
- The polygon to drawtransform
- The coordinate transform
-
outline
public void outline(com.badlogic.gdx.math.Rectangle rect) Outlines the given rectangle with the current color and texture.The drawing will be a wireframe of a rectangle. The wireframe will be textured with Texture coordinate (0,1) at the bottom left corner identified by rect,origin. The remaining edges will correspond to the edges of the texture. To draw only part of a texture, use a subtexture to outline the edges with [minS,maxS]x[min,maxT]. Alternatively, you can use a
Poly2
for more fine-tuned control.- Parameters:
rect
- The rectangle to outline
-
outline
public void outline(float x, float y, float width, float height) Outlines the given rectangle with the current color and texture.The drawing will be a wireframe of a rectangle. The wireframe will be textured with Texture coordinate (0,1) at the bottom left corner identified by rect,origin. The remaining edges will correspond to the edges of the texture. To draw only part of a texture, use a subtexture to outline the edges with [minS,maxS]x[min,maxT]. Alternatively, you can use a
Poly2
for more fine-tuned control. If depth testing is on, all vertices will use the current sprite batch depth.- Parameters:
x
- x-coordinatey
- y-coordinatewidth
- width of outline boxheight
- height of outline box
-
outline
public void outline(com.badlogic.gdx.math.Rectangle rect, com.badlogic.gdx.math.Vector2 offset) Outlines the given rectangle with the current color and texture.The drawing will be a wireframe of a rectangle. The wireframe will be textured with Texture coordinate (0,1) at the bottom left corner identified by rect,origin. The remaining edges will correspond to the edges of the texture. To draw only part of a texture, use a subtexture to outline the edges with [minS,maxS]x[min,maxT]. Alternatively, you can use a
Poly2
for more fine-tuned control.- Parameters:
rect
- The rectangle to outlineoffset
- The rectangle offset
-
outline
public void outline(com.badlogic.gdx.math.Rectangle rect, float x, float y) Outlines the given rectangle with the current color and texture.The drawing will be a wireframe of a rectangle. The wireframe will be textured with Texture coordinate (0,1) at the bottom left corner identified by rect,origin. The remaining edges will correspond to the edges of the texture. To draw only part of a texture, use a subtexture to outline the edges with [minS,maxS]x[min,maxT]. Alternatively, you can use a
Poly2
for more fine-tuned control.- Parameters:
rect
- The rectangle to outlinex
- The rectangle x offsety
- The rectangle y offset
-
outline
public void outline(com.badlogic.gdx.math.Rectangle rect, com.badlogic.gdx.math.Vector2 origin, com.badlogic.gdx.math.Vector2 scale, float angle, com.badlogic.gdx.math.Vector2 offset) Outlines the given rectangle with the current color and texture.The rectangle will be scaled first, then rotated, and finally offset by the given position. Rotation is measured in radians and is counter clockwise from the x-axis. Rotation will be about the provided origin, which is specified relative to the origin of the rectangle (not world coordinates). So to spin about the center, the origin should be width/2, height/2 of the rectangle.
The drawing will be a wireframe of a rectangle. The wireframe will be textured with Texture coordinate (0,1) at the bottom left corner identified by rect,origin. The remaining edges will correspond to the edges of the texture. To draw only part of a texture, use a subtexture to outline the edges with [minS,maxS]x[min,maxT]. Alternatively, you can use a
Poly2
for more fine-tuned control.- Parameters:
rect
- The rectangle to outlineorigin
- The rotational offset in the rectanglescale
- The amount to scale the rectangleangle
- The amount to rotate the rectangleoffset
- The rectangle offset in world coordinates
-
outline
public void outline(com.badlogic.gdx.math.Rectangle rect, com.badlogic.gdx.math.Affine2 transform) Outlines the given rectangle with the current color and texture.The rectangle will transformed by the given matrix. The transform will be applied to the origin of the rectangle (not world coordinates).
The drawing will be a wireframe of a rectangle. The wireframe will be textured with Texture coordinate (0,1) at the bottom left corner identified by rect,origin. The remaining edges will correspond to the edges of the texture. To draw only part of a texture, use a subtexture to outline the edges with [minS,maxS]x[min,maxT]. Alternatively, you can use a
Poly2
for more fine-tuned control.- Parameters:
rect
- The rectangle to outlinetransform
- The coordinate transform
-
outline
Outlines the given path with the current color and texture.The drawing will be a wireframe of a path, but the lines are textured. The vertex coordinates will be determined by path vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply outlining the rectangle.
One way to think of the path is as a "cookie cutter". Treat the path coordinates as pixel coordinates in the texture file, and use that to determine how the texture fills the path. This may make the path larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this.
- Parameters:
path
- The path to outline
-
outline
Outlines the given path with the current color and texture.The path will be offset by the given position.
The drawing will be a wireframe of a path, but the lines are textured. The vertex coordinates will be determined by path vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply outlining the rectangle.
One way to think of the path is as a "cookie cutter". Treat the path coordinates as pixel coordinates in the texture file, and use that to determine how the texture fills the path. This may make the path larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this.
- Parameters:
path
- The path to outlineoffset
- The path offset
-
outline
Outlines the given path with the current color and texture.The path will be offset by the given position.
The drawing will be a wireframe of a path, but the lines are textured. The vertex coordinates will be determined by path vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply outlining the rectangle.
One way to think of the path is as a "cookie cutter". Treat the path coordinates as pixel coordinates in the texture file, and use that to determine how the texture fills the path. This may make the path larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this.
- Parameters:
path
- The path to outlinex
- The x offsety
- The y offset
-
outline
public void outline(Path2 path, com.badlogic.gdx.math.Vector2 origin, com.badlogic.gdx.math.Vector2 scale, float angle, com.badlogic.gdx.math.Vector2 offset) Outlines the given path with the current color and texture.The path will be scaled first, then rotated, and finally offset by the given position. Rotation is measured in radians and is counter clockwise from the x-axis. Rotation will be about the provided origin, which is specified relative to the origin of the path (not world coordinates). Hence this origin is essentially the pixel coordinate of the texture (see below) to assign as the rotational center.
The drawing will be a wireframe of a path, but the lines are textured. The vertex coordinates will be determined by path vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply outlining the rectangle.
One way to think of the path is as a "cookie cutter". Treat the path coordinates as pixel coordinates in the texture file, and use that to determine how the texture fills the path. This may make the path larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this.
- Parameters:
path
- The path to outlineorigin
- The image origin in pixel spacescale
- The amount to scale the pathangle
- The amount to rotate the pathoffset
- The path offset in world coordinates
-
outline
Outlines the given path with the current color and texture.The path will transformed by the given matrix. The transform will be applied to the origin of the path (not world coordinates). Hence this origin is essentially the pixel coordinate of the texture (see below) to assign as the origin of this transform.
The drawing will be a wireframe of a path, but the lines are textured. The vertex coordinates will be determined by path vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply outlining the rectangle.
One way to think of the path is as a "cookie cutter". Treat the path coordinates as pixel coordinates in the texture file, and use that to determine how the texture fills the path. This may make the path larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this.
- Parameters:
path
- The path to outlinetransform
- The transform to be applied
-
drawMesh
Draws the given mesh with the current texture and/or gradient.This method provides more fine tuned control over texture coordinates that the other fill/outline methods. The texture no longer needs to be drawn uniformly over the shape. The offset will be applied to the vertex positions directly in world space.
The drawing command will be determined by the mesh, and the triangulation or lines determined by the mesh indices. The mesh vertices use their own color values. However, if tint is true, these values will be tinted (i.e. multiplied) by the current active color.
- Parameters:
mesh
- The sprite meshoffset
- The coordinate offset for the meshtint
- Whether to tint with the active color
-
drawMesh
Draws the given mesh with the current texture and/or gradient.This method provides more fine tuned control over texture coordinates that the other fill/outline methods. The texture no longer needs to be drawn uniformly over the shape. The offset will be applied to the vertex positions directly in world space.
The drawing command will be determined by the mesh, and the triangulation or lines determined by the mesh indices. The mesh vertices use their own color values. However, if tint is true, these values will be tinted (i.e. multiplied) by the current active color.
- Parameters:
mesh
- The sprite meshx
- The x-coordinate offset for the meshy
- The y-coordinate offset for the meshtint
- Whether to tint with the active color
-
drawMesh
Draws the given mesh with the current texture and/or gradient.This method provides more fine tuned control over texture coordinates that the other fill/outline methods. The texture no longer needs to be drawn uniformly over the shape. The transform will be applied to the vertex positions directly in world space.
The drawing command will be determined by the mesh, and the triangulation or lines determined by the mesh indices. The mesh vertices use their own color values. However, if tint is true, these values will be tinted (i.e. multiplied) by the current active color.
- Parameters:
mesh
- The sprite meshtransform
- The coordinate transformtint
- Whether to tint with the active color
-
drawText
Draws the text on the screen.The text will be left-aligned with the origin at the baseline (e.g. the alignment is
TextAlign.baselineLeft
.This method will draw the font with the current sprite batch color. However, calling this method will erase the current texture.
- Parameters:
text
- The string to drawfont
- The font to use
-
drawText
Draws the text on the screen.The text will be left-aligned with the origin at the baseline (e.g. the alignment is
TextAlign.baselineLeft
. The origin will be offset by the given amount.This method will draw the font with the current sprite batch color. However, calling this method will erase the current texture.
- Parameters:
text
- The string to drawfont
- The font to usex
- The x-coordinate of the lower-left cornery
- The y-coordinate of the lower-left corner
-
drawText
public void drawText(String text, com.badlogic.gdx.graphics.g2d.BitmapFont font, com.badlogic.gdx.math.Vector2 pos) Draws the text on the screen.The text will be left-aligned with the origin at the baseline (e.g. the alignment is
TextAlign.baselineLeft
. The origin will be offset by the given amount.This method will draw the font with the current sprite batch color. However, calling this method will erase the current texture.
- Parameters:
text
- The string to drawfont
- The font to usepos
- The position of the lower-left corner
-
drawText
public void drawText(String text, com.badlogic.gdx.graphics.g2d.BitmapFont font, com.badlogic.gdx.math.Affine2 transform) Draws the text on the screen.The text will be left-aligned with the origin at the baseline (e.g. the alignment is
TextAlign.baselineLeft
. The text image will be transformed at this origin.This method will draw the font with the current sprite batch color. However, calling this method will erase the current texture.
- Parameters:
text
- The string to drawfont
- The font to usetransform
- The coordinate transform
-
drawText
Draws the formatted text on the screen.The text origin is defined by
TextLayout.getAlignment()
.This method will ignore the sprite batch color and use the color of the text layout. However, calling this method will erase the current texture.
- Parameters:
layout
- The text layout to draw
-
drawText
Draws the formatted text on the screen.The text origin is defined by
TextLayout.getAlignment()
. The origin will be offset by the given amount.This method will ignore the sprite batch color and use the color of the text layout. However, calling this method will erase the current texture.
- Parameters:
layout
- The text layout to drawx
- The x-coordinate of the layout originy
- The y-coordinate of the layout origin
-
drawText
Draws the formatted text on the screen.The text origin is defined by
TextLayout.getAlignment()
. The origin will be offset by the given amount.This method will ignore the sprite batch color and use the color of the text layout. However, calling this method will erase the current texture.
- Parameters:
layout
- The text layout to drawpos
- The position of the layout origin
-
drawText
Draws the formatted text on the screen.The text origin is defined by
TextLayout.getAlignment()
. The text image will be transformed at this origin.This method will ignore the sprite batch color and use the color of the text layout. However, calling this method will erase the current texture.
- Parameters:
layout
- The text layout to drawtransform
- The transform to apply to the text
-
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) 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
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.- Specified by:
draw
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- Parameters:
texture
- the image texturex
- 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/originY, in degreessrcX
- 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) Draws a rectangle with the bottom left corner at x,y having the given width and height in pixels.The portion of the
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.- Specified by:
draw
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- Parameters:
texture
- the image texturex
- 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(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.The portion of the
Texture
given by srcX, srcY and srcWidth, srcHeight are used. These coordinates and sizes are given in texels.- Specified by:
draw
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- Parameters:
texture
- the image texturex
- 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 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) Draws a rectangle with the bottom left corner at x,y having the given width and height in pixels.The portion of the
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 tintColor
.- Specified by:
draw
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- Parameters:
texture
- the image texturex
- the x-coordinate in screen spacey
- the y-coordinate in screen spacewidth
- the width in pixelsheight
- the height in pixelsu
- the Texture region u valuev
- the Texture region u valueu2
- the Texture region u2 valuev2
- the Texture region v2 value
-
draw
public 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.- Specified by:
draw
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- Parameters:
texture
- the image texturex
- the x-coordinate in screen spacey
- the y-coordinate in screen space
-
draw
public 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.- Specified by:
draw
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- Parameters:
texture
- the image texturex
- the x-coordinate in screen spacey
- the y-coordinate in screen spacewidth
- the image width in screen spaceheight
- the image height in screen space
-
draw
public void draw(com.badlogic.gdx.graphics.Texture texture, float[] spriteVertices, int offset, int count) Draws a rectangle using the given vertices.There must be a multiple of 4 vertices, each made up of 5 elements in this order: x, y, color, u, v. If count is not a multiple of 20 (4 vertices of 5 elements), then any remaining vertices are ignored. The
getColor()
from the Batch is not applied.- Specified by:
draw
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- Parameters:
texture
- the image texturespriteVertices
- the sprite meshoffset
- the starting offset in spriteVerticescount
- the number of element in spriteVertices to use
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.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.- Specified by:
draw
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- Parameters:
region
- the image texture regionx
- the x-coordinate in screen spacey
- the y-coordinate in screen space
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.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.- Specified by:
draw
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- Parameters:
region
- the image texture regionx
- the x-coordinate in screen spacey
- the y-coordinate in screen spacewidth
- the image width in screen spaceheight
- the image height in screen space
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.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.
- Specified by:
draw
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- Parameters:
region
- the image texture regionx
- 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/originY, in degrees
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.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 by the given amount.The bottom left corner is at x,y and stretches 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 (or clockwise) rotation of the rectangle around originX, originY.
- Specified by:
draw
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- Parameters:
region
- the image texture regionx
- 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 rotation of the rectangle around originX/originY, in degreesclockwise
- whether to rotate clockwise (default is counter clockwise)
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.TextureRegion region, float width, float height, com.badlogic.gdx.math.Affine2 transform) Draws a rectangle transformed by the given matrix.The rectangle has the given width and height. The untransformed origin is (0,0)
- Specified by:
draw
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- Parameters:
region
- the image texture regionwidth
- the width in pixelsheight
- the height in pixelstransform
- the drawing transform
-
draw
public void draw(com.badlogic.gdx.graphics.Texture texture, Poly2 poly, com.badlogic.gdx.math.Vector2 offset) Draws the textured polygon at the given positionThis is a convenience method that calls the appropriate fill method. It sets the texture, but not the color tint, deleting the previous value. It then draws the polygon, offset by the given value.
The polygon tesselation will be determined by the indices in poly. If the polygon has not been triangulated, it may not draw properly.
The vertex coordinates will be determined by polygon vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply drawing the texture.
One way to think of the polygon is as a "cookie cutter". Treat the polygon coordinates as pixel coordinates in the texture filed, and use that to determine how the texture fills the polygon. This may make the polygon larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this.
- Parameters:
texture
- The new texturepoly
- The polygon to textureoffset
- The polygon offset
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.TextureRegion region, Poly2 poly, com.badlogic.gdx.math.Vector2 offset) Draws the textured polygon at the given positionThis is a convenience method that calls the appropriate fill method. It sets the texture, but not the color tint, deleting the previous value. It then draws the polygon, offset by the given value.
The polygon tesselation will be determined by the indices in poly. If the polygon has not been triangulated, it may not draw properly.
The vertex coordinates will be determined by polygon vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply drawing the texture.
One way to think of the polygon is as a "cookie cutter". Treat the polygon coordinates as pixel coordinates in the texture filed, and use that to determine how the texture fills the polygon. This may make the polygon larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this.
- Parameters:
region
- The new texture regionpoly
- The polygon to textureoffset
- The polygon offset
-
draw
Draws the textured polygon at the given positionThis is a convenience method that calls the appropriate fill method. It sets the texture, but not the color tint, deleting the previous value. It then draws the polygon, offset by the given value.
The polygon tesselation will be determined by the indices in poly. If the polygon has not been triangulated, it may not draw properly.
The vertex coordinates will be determined by polygon vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply drawing the texture.
One way to think of the polygon is as a "cookie cutter". Treat the polygon coordinates as pixel coordinates in the texture filed, and use that to determine how the texture fills the polygon. This may make the polygon larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this.
- Parameters:
texture
- The new texturepoly
- The polygon to texturex
- The polygon x offsety
- The polygon y offset
-
draw
Draws the textured polygon at the given positionThis is a convenience method that calls the appropriate fill method. It sets the texture, but not the color tint, deleting the previous value. It then draws the polygon, offset by the given value.
The polygon tesselation will be determined by the indices in poly. If the polygon has not been triangulated, it may not draw properly.
The vertex coordinates will be determined by polygon vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply drawing the texture.
One way to think of the polygon is as a "cookie cutter". Treat the polygon coordinates as pixel coordinates in the texture filed, and use that to determine how the texture fills the polygon. This may make the polygon larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this.
- Parameters:
region
- The new texture regionpoly
- The polygon to texturex
- The polygon x offsety
- The polygon y offset
-
draw
public void draw(com.badlogic.gdx.graphics.Texture texture, Poly2 poly, com.badlogic.gdx.math.Affine2 transform) Draws the given polygon of the texture with the transform.This is a convenience method that calls the appropriate fill method. It sets the texture, but not the color tint, deleting the previous value. It then draws the polygon, offset by the given value.
The polygon tesselation will be determined by the indices in poly. If the polygon has not been triangulated, it may not draw properly.
The vertex coordinates will be determined by polygon vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply drawing the texture.
One way to think of the polygon is as a "cookie cutter". Treat the polygon coordinates as pixel coordinates in the texture filed, and use that to determine how the texture fills the polygon. This may make the polygon larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this.
- Parameters:
texture
- The new texturepoly
- The polygon to texturetransform
- The drawing transform
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.TextureRegion region, Poly2 poly, com.badlogic.gdx.math.Affine2 transform) Draws the given polygon of the texture with the transform.This is a convenience method that calls the appropriate fill method. It sets the texture, but not the color tint, deleting the previous value. It then draws the polygon, offset by the given value.
The polygon tesselation will be determined by the indices in poly. If the polygon has not been triangulated, it may not draw properly.
The vertex coordinates will be determined by polygon vertex position. A horizontal position x has texture coordinate x/texture.width. A vertical coordinate has texture coordinate 1-y/texture.height. As a result, a rectangular polygon that has the same dimensions as the texture is the same as simply drawing the texture.
One way to think of the polygon is as a "cookie cutter". Treat the polygon coordinates as pixel coordinates in the texture filed, and use that to determine how the texture fills the polygon. This may make the polygon larger than you like in order to get the appropriate texturing. You should use one of the transform methods to fix this.
- Parameters:
region
- The new texture regionpoly
- The polygon to texturetransform
- The drawing transform
-
draw
public void draw(com.badlogic.gdx.graphics.Texture texture, com.badlogic.gdx.math.Affine2 transform) Draws the the texture with the transform.This is a convenience method that calls the appropriate fill method. It sets the texture, but not the color tint, deleting the previous value. It then draws the texture rectangle transformed appropriately.
- Parameters:
texture
- The new texturetransform
- The drawing transform
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.TextureRegion region, com.badlogic.gdx.math.Affine2 transform) Draws the the texture with the transform.This is a convenience method that calls the appropriate fill method. It sets the texture, but not the color tint, deleting the previous value. It then draws the texture rectangle transformed appropriately.
- Parameters:
region
- The new texture regiontransform
- The drawing transform
-