public class SpriteCache extends Object implements Disposable
sprites
or textures
, first call beginCache()
, then call the
appropriate add method to define the images. To complete the cache, call endCache()
and store the returned
cache ID.begin()
, then call draw(int)
with a cache ID. When SpriteCache drawing
is complete, call end()
.resized
, the SpriteCache's matrices must be updated. For example:cache.getProjectionMatrix().setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
draw(int)
.Modifier and Type | Field and Description |
---|---|
int |
renderCalls
Number of render calls since the last
begin() . |
int |
totalRenderCalls
Number of rendering calls, ever.
|
Constructor and Description |
---|
SpriteCache()
Creates a cache that uses indexed geometry and can contain up to 1000 images.
|
SpriteCache(int size,
boolean useIndices)
Creates a cache with the specified size, using a default shader if OpenGL ES 2.0 is being used.
|
SpriteCache(int size,
ShaderProgram shader,
boolean useIndices)
Creates a cache with the specified size and OpenGL ES 2.0 shader.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Sprite sprite)
Adds the specified sprite to the cache.
|
void |
add(Texture texture,
float[] vertices,
int offset,
int length)
Adds the specified vertices to the cache.
|
void |
add(Texture texture,
float x,
float y)
Adds the specified texture to the cache.
|
void |
add(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)
Adds the specified texture to the cache.
|
void |
add(Texture texture,
float x,
float y,
float width,
float height,
int srcX,
int srcY,
int srcWidth,
int srcHeight,
boolean flipX,
boolean flipY)
Adds the specified texture to the cache.
|
void |
add(Texture texture,
float x,
float y,
int srcWidth,
int srcHeight,
float u,
float v,
float u2,
float v2,
float color)
Adds the specified texture to the cache.
|
void |
add(Texture texture,
float x,
float y,
int srcX,
int srcY,
int srcWidth,
int srcHeight)
Adds the specified texture to the cache.
|
void |
add(TextureRegion region,
float x,
float y)
Adds the specified region to the cache.
|
void |
add(TextureRegion region,
float x,
float y,
float width,
float height)
Adds the specified region to the cache.
|
void |
add(TextureRegion region,
float x,
float y,
float originX,
float originY,
float width,
float height,
float scaleX,
float scaleY,
float rotation)
Adds the specified region to the cache.
|
void |
begin()
Prepares the OpenGL state for SpriteCache rendering.
|
void |
beginCache()
Starts the definition of a new cache, allowing the add and
endCache() methods to be called. |
void |
beginCache(int cacheID)
Starts the redefinition of an existing cache, allowing the add and
endCache() methods to be called. |
void |
clear()
Invalidates all cache IDs and resets the SpriteCache so new caches can be added.
|
void |
dispose()
Releases all resources held by this SpriteCache.
|
void |
draw(int cacheID)
Draws all the images defined for the specified cache ID.
|
void |
draw(int cacheID,
int offset,
int length)
Draws a subset of images defined for the specified cache ID.
|
void |
end()
Completes rendering for this SpriteCache.
|
int |
endCache()
Ends the definition of a cache, returning the cache ID to be used with
draw(int) . |
Color |
getColor() |
Matrix4 |
getProjectionMatrix() |
Matrix4 |
getTransformMatrix() |
void |
setColor(Color tint)
Sets the color used to tint images when they are added to the SpriteCache.
|
void |
setColor(float color) |
void |
setColor(float r,
float g,
float b,
float a) |
void |
setProjectionMatrix(Matrix4 projection) |
void |
setShader(ShaderProgram shader)
Sets the shader to be used in a GLES 2.0 environment.
|
void |
setTransformMatrix(Matrix4 transform) |
public int renderCalls
begin()
.public int totalRenderCalls
public SpriteCache()
public SpriteCache(int size, boolean useIndices)
size
- The maximum number of images this cache can hold. The memory required to hold the images is allocated up front.
Max of 5460 if indices are used.useIndices
- If true, indexed geometry will be used.public SpriteCache(int size, ShaderProgram shader, boolean useIndices)
size
- The maximum number of images this cache can hold. The memory required to hold the images is allocated up front.
Max of 5460 if indices are used.useIndices
- If true, indexed geometry will be used.public void setColor(Color tint)
Color.WHITE
.public void setColor(float r, float g, float b, float a)
setColor(Color)
public void setColor(float color)
setColor(Color)
,
Color.toFloatBits()
public Color getColor()
public void beginCache()
endCache()
methods to be called.public void beginCache(int cacheID)
endCache()
methods to be called. If this is not
the last cache created, it cannot have more entries added to it than when it was first created. To do that, use
clear()
and then begin()
.public int endCache()
draw(int)
.public void clear()
public void add(Texture texture, float[] vertices, int offset, int length)
public void add(Texture texture, float x, float y)
public void add(Texture texture, float x, float y, int srcWidth, int srcHeight, float u, float v, float u2, float v2, float color)
public void add(Texture texture, float x, float y, int srcX, int srcY, int srcWidth, int srcHeight)
public void add(Texture texture, float x, float y, float width, float height, int srcX, int srcY, int srcWidth, int srcHeight, boolean flipX, boolean flipY)
public void add(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)
public void add(TextureRegion region, float x, float y)
public void add(TextureRegion region, float x, float y, float width, float height)
public void add(TextureRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation)
public void add(Sprite sprite)
public void begin()
public void end()
public void draw(int cacheID)
public void draw(int cacheID, int offset, int length)
offset
- The first image to render.length
- The number of images from the first image (inclusive) to render.public void dispose()
dispose
in interface Disposable
public Matrix4 getProjectionMatrix()
public void setProjectionMatrix(Matrix4 projection)
public Matrix4 getTransformMatrix()
public void setTransformMatrix(Matrix4 transform)
public void setShader(ShaderProgram shader)
shader
- the ShaderProgram
or null to use the default shader.Copyright © 2015. All rights reserved.