Package com.prineside.tdi2.utils
Class SpriteCacheExtended
java.lang.Object
com.badlogic.gdx.graphics.g2d.SpriteCache
com.prineside.tdi2.utils.SpriteCacheExtended
- All Implemented Interfaces:
com.badlogic.gdx.graphics.g2d.Batch
,com.badlogic.gdx.utils.Disposable
public final class SpriteCacheExtended
extends com.badlogic.gdx.graphics.g2d.SpriteCache
implements com.badlogic.gdx.graphics.g2d.Batch
May also act like a Batch but will store vertex data into cache.
Batch's methods related to blending won't work and will throw an exception (blending should be applied
during the rendering stage, not while mesh generation).
If some batch is specified by setOutputToBatch(), Batch-defined methods will be redirected there.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionint
int
final int
final int
final boolean
final int
Fields inherited from class com.badlogic.gdx.graphics.g2d.SpriteCache
renderCalls, totalRenderCalls
Fields 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
ConstructorsConstructorDescriptionSpriteCacheExtended
(String name, int size, com.badlogic.gdx.graphics.glutils.ShaderProgram shaderProgram, boolean useIndices) -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(com.badlogic.gdx.graphics.Texture texture, float[] vertices, int offset, int length) Adds the specified vertices to the cache.void
Starts the definition of a new cache, allowing the add andSpriteCache.endCache()
methods to be called.void
clear()
Invalidates all cache IDs and resets the SpriteCache so new caches can be added.static com.badlogic.gdx.graphics.glutils.ShaderProgram
Taken from SpriteCachevoid
Disables blending for drawing sprites.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 rotated 90 degrees.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.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) Deprecated.SpriteCache#add(Texture texture, float x, float y, int srcWidth, int srcHeight, float u, float v, float u2, float v2, float color) may be broken / inconsistent (srcWidth/Height define actual size and not the source size), better use some other method.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
Enables blending for drawing sprites.int
endCache()
Ends the definition of a cache, returning the cache ID to be used withSpriteCache.draw(int)
.void
flush()
Causes any pending sprites to be rendered, without ending the Batch.int
int
int
int
com.badlogic.gdx.graphics.glutils.ShaderProgram
boolean
boolean
isFull()
void
setAlphaMultiplier
(float fixedAlpha) 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
setOutputToBatch
(com.badlogic.gdx.graphics.g2d.Batch batch) Redirects all of the calls to the specified batch SpriteCache begins to act like a regular batch Batch uses indicesMethods inherited from class com.badlogic.gdx.graphics.g2d.SpriteCache
add, add, add, add, add, add, add, add, add, begin, beginCache, dispose, draw, draw, end, getColor, getCustomShader, getPackedColor, getProjectionMatrix, getTransformMatrix, isDrawing, setColor, setColor, setPackedColor, setProjectionMatrix, setShader, setTransformMatrix
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.badlogic.gdx.graphics.g2d.Batch
begin, end, getColor, getPackedColor, getProjectionMatrix, getTransformMatrix, isDrawing, setColor, setColor, setPackedColor, setProjectionMatrix, setShader, setTransformMatrix
Methods inherited from interface com.badlogic.gdx.utils.Disposable
dispose
-
Field Details
-
useIndices
public final boolean useIndices -
vertexPerAdd
public final int vertexPerAdd -
size
public final int size -
maxAdds
public final int maxAdds -
addCount
public int addCount -
lastCacheId
public int lastCacheId
-
-
Constructor Details
-
SpriteCacheExtended
public SpriteCacheExtended(String name, int size, com.badlogic.gdx.graphics.glutils.ShaderProgram shaderProgram, boolean useIndices)
-
-
Method Details
-
setOutputToBatch
public void setOutputToBatch(com.badlogic.gdx.graphics.g2d.Batch batch) Redirects all of the calls to the specified batch SpriteCache begins to act like a regular batch Batch uses indices -
setAlphaMultiplier
public void setAlphaMultiplier(float fixedAlpha) -
createDefaultShader
public static com.badlogic.gdx.graphics.glutils.ShaderProgram createDefaultShader()Taken from SpriteCache -
add
public void add(com.badlogic.gdx.graphics.Texture texture, float[] vertices, int offset, int length) Description copied from class:com.badlogic.gdx.graphics.g2d.SpriteCache
Adds the specified vertices to the cache. Each vertex should have 5 elements, one for each of the attributes: x, y, color, u, and v. If indexed geometry is used, each image should be specified as 4 vertices, otherwise each image should be specified as 6 vertices.- Overrides:
add
in classcom.badlogic.gdx.graphics.g2d.SpriteCache
-
beginCache
public void beginCache()Description copied from class:com.badlogic.gdx.graphics.g2d.SpriteCache
Starts the definition of a new cache, allowing the add andSpriteCache.endCache()
methods to be called.- Overrides:
beginCache
in classcom.badlogic.gdx.graphics.g2d.SpriteCache
-
isFull
public boolean isFull() -
endCache
public int endCache()Description copied from class:com.badlogic.gdx.graphics.g2d.SpriteCache
Ends the definition of a cache, returning the cache ID to be used withSpriteCache.draw(int)
.- Overrides:
endCache
in classcom.badlogic.gdx.graphics.g2d.SpriteCache
-
clear
public void clear()Description copied from class:com.badlogic.gdx.graphics.g2d.SpriteCache
Invalidates all cache IDs and resets the SpriteCache so new caches can be added.- Overrides:
clear
in classcom.badlogic.gdx.graphics.g2d.SpriteCache
-
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:com.badlogic.gdx.graphics.g2d.Batch
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 interfacecom.badlogic.gdx.graphics.g2d.Batch
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:com.badlogic.gdx.graphics.g2d.Batch
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 interfacecom.badlogic.gdx.graphics.g2d.Batch
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(com.badlogic.gdx.graphics.Texture texture, float x, float y, int srcX, int srcY, int srcWidth, int srcHeight) Description copied from interface:com.badlogic.gdx.graphics.g2d.Batch
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.- Specified by:
draw
in interfacecom.badlogic.gdx.graphics.g2d.Batch
x
- the x-coordinate in screen spacey
- the y-coordinate in screen spacesrcX
- the x-coordinate in texel spacesrcY
- the y-coordinate in texel spacesrcWidth
- the source with in texelssrcHeight
- the source height in texels
-
draw
@Deprecated 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) Deprecated.SpriteCache#add(Texture texture, float x, float y, int srcWidth, int srcHeight, float u, float v, float u2, float v2, float color) may be broken / inconsistent (srcWidth/Height define actual size and not the source size), better use some other method.Description copied from interface:com.badlogic.gdx.graphics.g2d.Batch
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
.- Specified by:
draw
in interfacecom.badlogic.gdx.graphics.g2d.Batch
x
- the x-coordinate in screen spacey
- the y-coordinate in screen spacewidth
- the width in pixelsheight
- the height in pixels
-
draw
public void draw(com.badlogic.gdx.graphics.Texture texture, float x, float y) Description copied from interface:com.badlogic.gdx.graphics.g2d.Batch
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
x
- 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) Description copied from interface:com.badlogic.gdx.graphics.g2d.Batch
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
-
draw
public void draw(com.badlogic.gdx.graphics.Texture texture, float[] spriteVertices, int offset, int count) Description copied from interface:com.badlogic.gdx.graphics.g2d.Batch
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. TheBatch.getColor()
from the Batch is not applied.- Specified by:
draw
in interfacecom.badlogic.gdx.graphics.g2d.Batch
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.TextureRegion region, float x, float y) Description copied from interface:com.badlogic.gdx.graphics.g2d.Batch
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
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.TextureRegion region, float x, float y, float width, float height) Description copied from interface:com.badlogic.gdx.graphics.g2d.Batch
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
-
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) Description copied from interface:com.badlogic.gdx.graphics.g2d.Batch
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
-
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) Description copied from interface:com.badlogic.gdx.graphics.g2d.Batch
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.- Specified by:
draw
in interfacecom.badlogic.gdx.graphics.g2d.Batch
clockwise
- If true, the texture coordinates are rotated 90 degrees clockwise. If false, they are rotated 90 degrees counter clockwise.
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.TextureRegion region, float width, float height, com.badlogic.gdx.math.Affine2 transform) Description copied from interface:com.badlogic.gdx.graphics.g2d.Batch
Draws a rectangle transformed by the given matrix.- Specified by:
draw
in interfacecom.badlogic.gdx.graphics.g2d.Batch
-
flush
public void flush()Description copied from interface:com.badlogic.gdx.graphics.g2d.Batch
Causes any pending sprites to be rendered, without ending the Batch.- Specified by:
flush
in interfacecom.badlogic.gdx.graphics.g2d.Batch
-
disableBlending
public void disableBlending()Description copied from interface:com.badlogic.gdx.graphics.g2d.Batch
Disables blending for drawing sprites. Calling this withinBatch.begin()
/Batch.end()
will flush the batch.- Specified by:
disableBlending
in interfacecom.badlogic.gdx.graphics.g2d.Batch
-
enableBlending
public void enableBlending()Description copied from interface:com.badlogic.gdx.graphics.g2d.Batch
Enables blending for drawing sprites. Calling this withinBatch.begin()
/Batch.end()
will flush the batch.- Specified by:
enableBlending
in interfacecom.badlogic.gdx.graphics.g2d.Batch
-
setBlendFunction
public void setBlendFunction(int srcFunc, int dstFunc) Description copied from interface:com.badlogic.gdx.graphics.g2d.Batch
Sets the blending function to be used when rendering sprites.- Specified by:
setBlendFunction
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- 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:com.badlogic.gdx.graphics.g2d.Batch
Sets separate (color/alpha) blending function to be used when rendering sprites.- Specified by:
setBlendFunctionSeparate
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- 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 interfacecom.badlogic.gdx.graphics.g2d.Batch
-
getBlendDstFunc
public int getBlendDstFunc()- Specified by:
getBlendDstFunc
in interfacecom.badlogic.gdx.graphics.g2d.Batch
-
getBlendSrcFuncAlpha
public int getBlendSrcFuncAlpha()- Specified by:
getBlendSrcFuncAlpha
in interfacecom.badlogic.gdx.graphics.g2d.Batch
-
getBlendDstFuncAlpha
public int getBlendDstFuncAlpha()- Specified by:
getBlendDstFuncAlpha
in interfacecom.badlogic.gdx.graphics.g2d.Batch
-
getShader
public com.badlogic.gdx.graphics.glutils.ShaderProgram getShader()- Specified by:
getShader
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- Returns:
- the current
ShaderProgram
set byBatch.setShader(ShaderProgram)
or the defaultShader
-
isBlendingEnabled
public boolean isBlendingEnabled()- Specified by:
isBlendingEnabled
in interfacecom.badlogic.gdx.graphics.g2d.Batch
- Returns:
- true if blending for sprites is enabled
-