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 TypeFieldDescriptionintintfinal intfinal intfinal booleanfinal intFields inherited from class com.badlogic.gdx.graphics.g2d.SpriteCache
renderCalls, totalRenderCallsFields 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 TypeMethodDescriptionvoidadd(com.badlogic.gdx.graphics.Texture texture, float[] vertices, int offset, int length) Adds the specified vertices to the cache.voidStarts the definition of a new cache, allowing the add andSpriteCache.endCache()methods to be called.voidclear()Invalidates all cache IDs and resets the SpriteCache so new caches can be added.static com.badlogic.gdx.graphics.glutils.ShaderProgramTaken from SpriteCachevoidDisables blending for drawing sprites.voiddraw(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.voiddraw(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.voiddraw(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.voiddraw(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.voiddraw(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.voiddraw(com.badlogic.gdx.graphics.Texture texture, float[] spriteVertices, int offset, int count) Draws a rectangle using the given vertices.voiddraw(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.voiddraw(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.voiddraw(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.voiddraw(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.voiddraw(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.voiddraw(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.voidEnables blending for drawing sprites.intendCache()Ends the definition of a cache, returning the cache ID to be used withSpriteCache.draw(int).voidflush()Causes any pending sprites to be rendered, without ending the Batch.intintintintcom.badlogic.gdx.graphics.glutils.ShaderProgrambooleanbooleanisFull()voidsetAlphaMultiplier(float fixedAlpha) voidsetBlendFunction(int srcFunc, int dstFunc) Sets the blending function to be used when rendering sprites.voidsetBlendFunctionSeparate(int srcFuncColor, int dstFuncColor, int srcFuncAlpha, int dstFuncAlpha) Sets separate (color/alpha) blending function to be used when rendering sprites.voidsetOutputToBatch(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, setTransformMatrixMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.badlogic.gdx.graphics.g2d.Batch
begin, end, getColor, getPackedColor, getProjectionMatrix, getTransformMatrix, isDrawing, setColor, setColor, setPackedColor, setProjectionMatrix, setShader, setTransformMatrixMethods 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.SpriteCacheAdds 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:
addin classcom.badlogic.gdx.graphics.g2d.SpriteCache
-
beginCache
public void beginCache()Description copied from class:com.badlogic.gdx.graphics.g2d.SpriteCacheStarts the definition of a new cache, allowing the add andSpriteCache.endCache()methods to be called.- Overrides:
beginCachein classcom.badlogic.gdx.graphics.g2d.SpriteCache
-
isFull
public boolean isFull() -
endCache
public int endCache()Description copied from class:com.badlogic.gdx.graphics.g2d.SpriteCacheEnds the definition of a cache, returning the cache ID to be used withSpriteCache.draw(int).- Overrides:
endCachein classcom.badlogic.gdx.graphics.g2d.SpriteCache
-
clear
public void clear()Description copied from class:com.badlogic.gdx.graphics.g2d.SpriteCacheInvalidates all cache IDs and resets the SpriteCache so new caches can be added.- Overrides:
clearin 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.BatchDraws 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 theTexturegiven 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:
drawin interfacecom.badlogic.gdx.graphics.g2d.Batchx- 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.BatchDraws a rectangle with the bottom left corner at x,y having the given width and height in pixels. The portion of theTexturegiven 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:
drawin interfacecom.badlogic.gdx.graphics.g2d.Batchx- 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.BatchDraws a rectangle with the bottom left corner at x,y having the given width and height in pixels. The portion of theTexturegiven by srcX, srcY and srcWidth, srcHeight are used. These coordinates and sizes are given in texels.- Specified by:
drawin interfacecom.badlogic.gdx.graphics.g2d.Batchx- 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.BatchDraws a rectangle with the bottom left corner at x,y having the given width and height in pixels. The portion of theTexturegiven 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:
drawin interfacecom.badlogic.gdx.graphics.g2d.Batchx- 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.BatchDraws a rectangle with the bottom left corner at x,y having the width and height of the texture.- Specified by:
drawin interfacecom.badlogic.gdx.graphics.g2d.Batchx- 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.BatchDraws a rectangle with the bottom left corner at x,y and stretching the region to cover the given width and height.- Specified by:
drawin 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.BatchDraws 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:
drawin 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.BatchDraws a rectangle with the bottom left corner at x,y having the width and height of the region.- Specified by:
drawin 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.BatchDraws a rectangle with the bottom left corner at x,y and stretching the region to cover the given width and height.- Specified by:
drawin 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.BatchDraws 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:
drawin 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.BatchDraws 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:
drawin interfacecom.badlogic.gdx.graphics.g2d.Batchclockwise- 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.BatchDraws a rectangle transformed by the given matrix.- Specified by:
drawin interfacecom.badlogic.gdx.graphics.g2d.Batch
-
flush
public void flush()Description copied from interface:com.badlogic.gdx.graphics.g2d.BatchCauses any pending sprites to be rendered, without ending the Batch.- Specified by:
flushin interfacecom.badlogic.gdx.graphics.g2d.Batch
-
disableBlending
public void disableBlending()Description copied from interface:com.badlogic.gdx.graphics.g2d.BatchDisables blending for drawing sprites. Calling this withinBatch.begin()/Batch.end()will flush the batch.- Specified by:
disableBlendingin interfacecom.badlogic.gdx.graphics.g2d.Batch
-
enableBlending
public void enableBlending()Description copied from interface:com.badlogic.gdx.graphics.g2d.BatchEnables blending for drawing sprites. Calling this withinBatch.begin()/Batch.end()will flush the batch.- Specified by:
enableBlendingin interfacecom.badlogic.gdx.graphics.g2d.Batch
-
setBlendFunction
public void setBlendFunction(int srcFunc, int dstFunc) Description copied from interface:com.badlogic.gdx.graphics.g2d.BatchSets the blending function to be used when rendering sprites.- Specified by:
setBlendFunctionin 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.BatchSets separate (color/alpha) blending function to be used when rendering sprites.- Specified by:
setBlendFunctionSeparatein 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:
getBlendSrcFuncin interfacecom.badlogic.gdx.graphics.g2d.Batch
-
getBlendDstFunc
public int getBlendDstFunc()- Specified by:
getBlendDstFuncin interfacecom.badlogic.gdx.graphics.g2d.Batch
-
getBlendSrcFuncAlpha
public int getBlendSrcFuncAlpha()- Specified by:
getBlendSrcFuncAlphain interfacecom.badlogic.gdx.graphics.g2d.Batch
-
getBlendDstFuncAlpha
public int getBlendDstFuncAlpha()- Specified by:
getBlendDstFuncAlphain interfacecom.badlogic.gdx.graphics.g2d.Batch
-
getShader
public com.badlogic.gdx.graphics.glutils.ShaderProgram getShader()- Specified by:
getShaderin interfacecom.badlogic.gdx.graphics.g2d.Batch- Returns:
- the current
ShaderProgramset byBatch.setShader(ShaderProgram)or the defaultShader
-
isBlendingEnabled
public boolean isBlendingEnabled()- Specified by:
isBlendingEnabledin interfacecom.badlogic.gdx.graphics.g2d.Batch- Returns:
- true if blending for sprites is enabled
-