Class SpriteCacheExtended

java.lang.Object
com.badlogic.gdx.graphics.g2d.SpriteCache
com.prineside.tdi2.utils.SpriteCacheExtended
All Implemented Interfaces:
Batch, Disposable

public final class SpriteCacheExtended extends SpriteCache implements 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.
  • 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, ShaderProgram shaderProgram, boolean useIndices)
  • Method Details

    • setOutputToBatch

      public void setOutputToBatch(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 ShaderProgram createDefaultShader()
      Taken from SpriteCache
    • add

      public void add(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 class 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 and SpriteCache.endCache() methods to be called.
      Overrides:
      beginCache in class 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 with SpriteCache.draw(int).
      Overrides:
      endCache in class 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 class SpriteCache
    • draw

      public void draw(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 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 interface Batch
      x - the x-coordinate in screen space
      y - the y-coordinate in screen space
      originX - the x-coordinate of the scaling and rotation origin relative to the screen space coordinates
      originY - the y-coordinate of the scaling and rotation origin relative to the screen space coordinates
      width - the width in pixels
      height - the height in pixels
      scaleX - the scale of the rectangle around originX/originY in x
      scaleY - the scale of the rectangle around originX/originY in y
      rotation - the angle of counter clockwise rotation of the rectangle around originX/originY, in degrees
      srcX - the x-coordinate in texel space
      srcY - the y-coordinate in texel space
      srcWidth - the source with in texels
      srcHeight - the source height in texels
      flipX - whether to flip the sprite horizontally
      flipY - whether to flip the sprite vertically
    • draw

      public void draw(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 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 interface Batch
      x - the x-coordinate in screen space
      y - the y-coordinate in screen space
      width - the width in pixels
      height - the height in pixels
      srcX - the x-coordinate in texel space
      srcY - the y-coordinate in texel space
      srcWidth - the source with in texels
      srcHeight - the source height in texels
      flipX - whether to flip the sprite horizontally
      flipY - whether to flip the sprite vertically
    • draw

      public void draw(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 the Texture given by srcX, srcY and srcWidth, srcHeight are used. These coordinates and sizes are given in texels.
      Specified by:
      draw in interface Batch
      x - the x-coordinate in screen space
      y - the y-coordinate in screen space
      srcX - the x-coordinate in texel space
      srcY - the y-coordinate in texel space
      srcWidth - the source with in texels
      srcHeight - the source height in texels
    • draw

      @Deprecated public void draw(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 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 tint Color.
      Specified by:
      draw in interface Batch
      x - the x-coordinate in screen space
      y - the y-coordinate in screen space
      width - the width in pixels
      height - the height in pixels
    • draw

      public void draw(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 interface Batch
      x - the x-coordinate in screen space
      y - the y-coordinate in screen space
    • draw

      public void draw(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 interface Batch
    • draw

      public void draw(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. The Batch.getColor() from the Batch is not applied.
      Specified by:
      draw in interface Batch
    • draw

      public void draw(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 interface Batch
    • draw

      public void draw(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 interface Batch
    • draw

      public void draw(TextureRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation)
      Description copied from interface: 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 interface Batch
      rotation - rotation in degrees
    • draw

      public void draw(TextureRegion region, float x, float y, float originX, float originY, float width, float height, float scaleX, float scaleY, float rotation, boolean clockwise)
      Description copied from interface: 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 interface Batch
      rotation - rotation in degrees
      clockwise - If true, the texture coordinates are rotated 90 degrees clockwise. If false, they are rotated 90 degrees counter clockwise.
    • draw

      public void draw(TextureRegion region, float width, float height, Affine2 transform)
      Description copied from interface: com.badlogic.gdx.graphics.g2d.Batch
      Draws a rectangle transformed by the given matrix.
      Specified by:
      draw in interface 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 interface Batch
    • disableBlending

      public void disableBlending()
      Description copied from interface: com.badlogic.gdx.graphics.g2d.Batch
      Disables blending for drawing sprites. Calling this within Batch.begin()/Batch.end() will flush the batch.
      Specified by:
      disableBlending in interface Batch
    • enableBlending

      public void enableBlending()
      Description copied from interface: com.badlogic.gdx.graphics.g2d.Batch
      Enables blending for drawing sprites. Calling this within Batch.begin()/Batch.end() will flush the batch.
      Specified by:
      enableBlending in interface 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 interface 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 interface 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 interface Batch
    • getBlendDstFunc

      public int getBlendDstFunc()
      Specified by:
      getBlendDstFunc in interface Batch
    • getBlendSrcFuncAlpha

      public int getBlendSrcFuncAlpha()
      Specified by:
      getBlendSrcFuncAlpha in interface Batch
    • getBlendDstFuncAlpha

      public int getBlendDstFuncAlpha()
      Specified by:
      getBlendDstFuncAlpha in interface Batch
    • getShader

      public ShaderProgram getShader()
      Specified by:
      getShader in interface Batch
      Returns:
      the current ShaderProgram set by Batch.setShader(ShaderProgram) or the defaultShader
    • isBlendingEnabled

      public boolean isBlendingEnabled()
      Specified by:
      isBlendingEnabled in interface Batch
      Returns:
      true if blending for sprites is enabled