Class Box2DSprite

java.lang.Object
com.badlogic.gdx.graphics.g2d.TextureRegion
com.badlogic.gdx.graphics.g2d.Sprite
net.dermetfan.gdx.graphics.g2d.Box2DSprite
Direct Known Subclasses:
AnimatedBox2DSprite

public class Box2DSprite
extends com.badlogic.gdx.graphics.g2d.Sprite
A Box2DSprite is a Sprite with additional drawing information and the ability to draw itself on a given Body or Fixture. It is supposed to be put in the user data of Fixtures or Bodies. Because geometrical information about bodies cannot be cached, it is faster to put Box2DSprites in the user data of Fixtures.
  • Field Summary

    Fields
    Modifier and Type Field Description
    static net.dermetfan.utils.Function<java.lang.Object,​Box2DSprite> defaultUserDataAccessor
    the userDataAccessor used by default
  • Constructor Summary

    Constructors
    Constructor Description
    Box2DSprite()  
    Box2DSprite​(com.badlogic.gdx.graphics.g2d.Sprite sprite)  
    Box2DSprite​(com.badlogic.gdx.graphics.g2d.TextureRegion region)  
    Box2DSprite​(com.badlogic.gdx.graphics.g2d.TextureRegion region, int srcX, int srcY, int srcWidth, int srcHeight)  
    Box2DSprite​(com.badlogic.gdx.graphics.Texture texture)  
    Box2DSprite​(com.badlogic.gdx.graphics.Texture texture, int srcWidth, int srcHeight)  
    Box2DSprite​(com.badlogic.gdx.graphics.Texture texture, int srcX, int srcY, int srcWidth, int srcHeight)  
  • Method Summary

    Modifier and Type Method Description
    void draw​(com.badlogic.gdx.graphics.g2d.Batch batch, float box2dX, float box2dY, float box2dWidth, float box2dHeight, float box2dRotation)
    Used internally.
    void draw​(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.physics.box2d.Body body)
    draws this Box2DSprite on the given Body
    void draw​(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.physics.box2d.Fixture fixture)
    draws this Box2DSprite on the given Fixture
    static void draw​(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.physics.box2d.World world)  
    static void draw​(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.physics.box2d.World world, boolean sortByZ)
    draws all the Box2DSprites on the Body or Fixture that hold them in their user data in the given World
    static net.dermetfan.utils.Function<?,​Box2DSprite> getUserDataAccessor()  
    static java.util.Comparator<Box2DSprite> getZComparator()  
    float getZIndex()  
    boolean isAdjustHeight()  
    boolean isAdjustWidth()  
    boolean isUseOriginX()  
    boolean isUseOriginY()  
    void setAdjustHeight​(boolean adjustHeight)  
    void setAdjustSize​(boolean adjustSize)  
    void setAdjustWidth​(boolean adjustWidth)  
    void setHeight​(float height)  
    void setUseOrigin​(boolean useOrigin)  
    void setUseOriginX​(boolean useOriginX)  
    void setUseOriginY​(boolean useOriginY)  
    static void setUserDataAccessor​(net.dermetfan.utils.Function<java.lang.Object,​Box2DSprite> userDataAccessor)  
    void setWidth​(float width)  
    static void setZComparator​(java.util.Comparator<Box2DSprite> zComparator)  
    void setZIndex​(float zIndex)  

    Methods inherited from class com.badlogic.gdx.graphics.g2d.Sprite

    draw, draw, flip, getBoundingRectangle, getColor, getHeight, getOriginX, getOriginY, getRotation, getScaleX, getScaleY, getVertices, getWidth, getX, getY, rotate, rotate90, scale, scroll, set, setAlpha, setBounds, setCenter, setCenterX, setCenterY, setColor, setColor, setFlip, setOrigin, setOriginBasedPosition, setOriginCenter, setPackedColor, setPosition, setRegion, setRotation, setScale, setScale, setSize, setU, setU2, setV, setV2, setX, setY, translate, translateX, translateY

    Methods inherited from class com.badlogic.gdx.graphics.g2d.TextureRegion

    getRegionHeight, getRegionWidth, getRegionX, getRegionY, getTexture, getU, getU2, getV, getV2, isFlipX, isFlipY, setRegion, setRegion, setRegion, setRegion, setRegionHeight, setRegionWidth, setRegionX, setRegionY, setTexture, split, split

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • defaultUserDataAccessor

      public static final net.dermetfan.utils.Function<java.lang.Object,​Box2DSprite> defaultUserDataAccessor
      the userDataAccessor used by default
  • Constructor Details

    • Box2DSprite

      public Box2DSprite()
      See Also:
      Sprite()
    • Box2DSprite

      public Box2DSprite​(com.badlogic.gdx.graphics.Texture texture, int srcWidth, int srcHeight)
      See Also:
      Sprite(Texture, int, int)
    • Box2DSprite

      public Box2DSprite​(com.badlogic.gdx.graphics.Texture texture, int srcX, int srcY, int srcWidth, int srcHeight)
      See Also:
      Sprite(Texture, int, int, int, int)
    • Box2DSprite

      public Box2DSprite​(com.badlogic.gdx.graphics.g2d.TextureRegion region, int srcX, int srcY, int srcWidth, int srcHeight)
      See Also:
      Sprite(TextureRegion, int, int, int, int)
    • Box2DSprite

      public Box2DSprite​(com.badlogic.gdx.graphics.Texture texture)
      See Also:
      Sprite(Texture)
    • Box2DSprite

      public Box2DSprite​(com.badlogic.gdx.graphics.g2d.TextureRegion region)
      See Also:
      Sprite(TextureRegion)
    • Box2DSprite

      public Box2DSprite​(com.badlogic.gdx.graphics.g2d.Sprite sprite)
      See Also:
      Sprite(Sprite)
  • Method Details

    • draw

      public static void draw​(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.physics.box2d.World world)
      See Also:
      draw(Batch, World, boolean)
    • draw

      public static void draw​(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.physics.box2d.World world, boolean sortByZ)
      draws all the Box2DSprites on the Body or Fixture that hold them in their user data in the given World
    • draw

      public void draw​(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.physics.box2d.Fixture fixture)
      draws this Box2DSprite on the given Fixture
    • draw

      public void draw​(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.physics.box2d.Body body)
      draws this Box2DSprite on the given Body
    • draw

      public void draw​(com.badlogic.gdx.graphics.g2d.Batch batch, float box2dX, float box2dY, float box2dWidth, float box2dHeight, float box2dRotation)
      Used internally. Draws this Box2DSprite in classic sprite coordinate system fashion with the given Box2D coordinates (combined with its own position, size and rotation).
      If useOriginX/Y is enabled, the origin will be used instead of calculating an appropriate one for the given Box2D coordinates.
      If adjustWidth/Height is disabled, the size of the drawing area of the sprite will be Sprite.width * Sprite.height instead of the given size.
      The drawing position of the sprite is always the bottom left of the body or fixture.
      Parameters:
      box2dX - the x coordinate (center) of the body or fixture
      box2dY - the y coordinate (center) of the body or fixture
      box2dWidth - the width of the body or fixture
      box2dHeight - the height of the body or fixture
      box2dRotation - the rotation of the body or fixture
    • getZIndex

      public float getZIndex()
      Returns:
      the zIndex
    • setZIndex

      public void setZIndex​(float zIndex)
      Parameters:
      zIndex - the zIndex to set
    • isAdjustWidth

      public boolean isAdjustWidth()
      Returns:
      the adjustWidth
    • setAdjustWidth

      public void setAdjustWidth​(boolean adjustWidth)
      Parameters:
      adjustWidth - the adjustWidth to set
    • isAdjustHeight

      public boolean isAdjustHeight()
      Returns:
      the adjustHeight
    • setAdjustHeight

      public void setAdjustHeight​(boolean adjustHeight)
      Parameters:
      adjustHeight - the adjustHeight to set
    • setAdjustSize

      public void setAdjustSize​(boolean adjustSize)
      Parameters:
      adjustSize - the adjustWidth and adjustHeight to set
    • isUseOriginX

      public boolean isUseOriginX()
      Returns:
      the useOriginX
    • setUseOriginX

      public void setUseOriginX​(boolean useOriginX)
      Parameters:
      useOriginX - the useOriginX to set
    • isUseOriginY

      public boolean isUseOriginY()
      Returns:
      the useOriginY
    • setUseOriginY

      public void setUseOriginY​(boolean useOriginY)
      Parameters:
      useOriginY - the useOriginY to set
    • setUseOrigin

      public void setUseOrigin​(boolean useOrigin)
      Parameters:
      useOrigin - the useOriginX and useOriginY to set
    • setWidth

      public void setWidth​(float width)
      See Also:
      Sprite.setSize(float, float)
    • setHeight

      public void setHeight​(float height)
      See Also:
      Sprite.setSize(float, float)
    • getZComparator

      public static java.util.Comparator<Box2DSprite> getZComparator()
      Returns:
      the zComparator
    • setZComparator

      public static void setZComparator​(java.util.Comparator<Box2DSprite> zComparator)
      Parameters:
      zComparator - the zComparator to set
    • getUserDataAccessor

      public static net.dermetfan.utils.Function<?,​Box2DSprite> getUserDataAccessor()
      Returns:
      the userDataAccessor
    • setUserDataAccessor

      public static void setUserDataAccessor​(net.dermetfan.utils.Function<java.lang.Object,​Box2DSprite> userDataAccessor)
      Parameters:
      userDataAccessor - the userDataAccessor to set