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
    Modifier and Type
    Class
    Description
    static final class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    int
     
    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

    Constructors
    Constructor
    Description
    SpriteCacheExtended(String name, int size, com.badlogic.gdx.graphics.glutils.ShaderProgram shaderProgram, boolean useIndices)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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 and SpriteCache.endCache() methods to be called.
    void
    Invalidates all cache IDs and resets the SpriteCache so new caches can be added.
    static com.badlogic.gdx.graphics.glutils.ShaderProgram
    Taken from SpriteCache
    void
    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
    Ends the definition of a cache, returning the cache ID to be used with SpriteCache.draw(int).
    void
    Causes any pending sprites to be rendered, without ending the Batch.
    int
     
    int
     
    int
     
    int
     
    com.badlogic.gdx.graphics.glutils.ShaderProgram
     
    boolean
     
    boolean
     
    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 indices

    Methods 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 class com.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 and SpriteCache.endCache() methods to be called.
      Overrides:
      beginCache in class com.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 with SpriteCache.draw(int).
      Overrides:
      endCache in class com.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 class com.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 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 com.badlogic.gdx.graphics.g2d.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
      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(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 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 com.badlogic.gdx.graphics.g2d.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(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 the Texture given by srcX, srcY and srcWidth, srcHeight are used. These coordinates and sizes are given in texels.
      Specified by:
      draw in interface com.badlogic.gdx.graphics.g2d.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(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 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 com.badlogic.gdx.graphics.g2d.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(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 interface com.badlogic.gdx.graphics.g2d.Batch
      x - the x-coordinate in screen space
      y - 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 interface com.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. The Batch.getColor() from the Batch is not applied.
      Specified by:
      draw in interface com.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 interface com.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 interface com.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 interface com.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 interface com.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 interface com.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 interface com.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 within Batch.begin()/Batch.end() will flush the batch.
      Specified by:
      disableBlending in interface com.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 within Batch.begin()/Batch.end() will flush the batch.
      Specified by:
      enableBlending in interface com.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 interface com.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 interface com.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 interface com.badlogic.gdx.graphics.g2d.Batch
    • getBlendDstFunc

      public int getBlendDstFunc()
      Specified by:
      getBlendDstFunc in interface com.badlogic.gdx.graphics.g2d.Batch
    • getBlendSrcFuncAlpha

      public int getBlendSrcFuncAlpha()
      Specified by:
      getBlendSrcFuncAlpha in interface com.badlogic.gdx.graphics.g2d.Batch
    • getBlendDstFuncAlpha

      public int getBlendDstFuncAlpha()
      Specified by:
      getBlendDstFuncAlpha in interface com.badlogic.gdx.graphics.g2d.Batch
    • getShader

      public com.badlogic.gdx.graphics.glutils.ShaderProgram getShader()
      Specified by:
      getShader in interface com.badlogic.gdx.graphics.g2d.Batch
      Returns:
      the current ShaderProgram set by Batch.setShader(ShaderProgram) or the defaultShader
    • isBlendingEnabled

      public boolean isBlendingEnabled()
      Specified by:
      isBlendingEnabled in interface com.badlogic.gdx.graphics.g2d.Batch
      Returns:
      true if blending for sprites is enabled