Class Box2DPolygonSprite

java.lang.Object
com.badlogic.gdx.graphics.g2d.PolygonSprite
net.dermetfan.gdx.graphics.g2d.Box2DPolygonSprite

public class Box2DPolygonSprite
extends com.badlogic.gdx.graphics.g2d.PolygonSprite
A Box2DPolygonSprite is a PolygonSprite 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 Box2DPolygonSprites in the user data of Fixtures.
Since:
0.5.0
  • Field Summary

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

    Constructors
    Constructor Description
    Box2DPolygonSprite​(com.badlogic.gdx.graphics.g2d.PolygonRegion region)  
    Box2DPolygonSprite​(com.badlogic.gdx.graphics.g2d.PolygonSprite sprite)  
  • 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 Box2DPolygonSprite on the given Body
    void draw​(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.physics.box2d.Fixture fixture)
    draws this Box2DPolygonSprite 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 Box2DPolygonSprites on the Body or Fixture that hold them in their user data in the given World
    void draw​(com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch batch, float box2dX, float box2dY, float box2dWidth, float box2dHeight, float box2dRotation)  
    static net.dermetfan.utils.Function<?,​Box2DPolygonSprite> getUserDataAccessor()  
    static java.util.Comparator<Box2DPolygonSprite> getZComparator()  
    float getZIndex()  
    boolean isAdjustHeight()  
    boolean isAdjustToPolygon()  
    boolean isAdjustWidth()  
    boolean isUseOriginX()  
    boolean isUseOriginY()  
    void setAdjustHeight​(boolean adjustHeight)  
    void setAdjustSize​(boolean adjustSize)  
    void setAdjustToPolygon​(boolean adjustToPolygon)  
    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,​Box2DPolygonSprite> userDataAccessor)  
    void setWidth​(float width)  
    static void setZComparator​(java.util.Comparator<Box2DPolygonSprite> zComparator)  
    void setZIndex​(float zIndex)  

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

    draw, draw, getBoundingRectangle, getColor, getHeight, getOriginX, getOriginY, getPackedColor, getRegion, getRotation, getScaleX, getScaleY, getVertices, getWidth, getX, getY, rotate, scale, set, setBounds, setColor, setColor, setOrigin, setPosition, setRegion, setRotation, setScale, setScale, setSize, setX, setY, translate, translateX, translateY

    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,​Box2DPolygonSprite> defaultUserDataAccessor
      the userDataAccessor used by default
  • Constructor Details

    • Box2DPolygonSprite

      public Box2DPolygonSprite​(com.badlogic.gdx.graphics.g2d.PolygonRegion region)
      See Also:
      PolygonSprite(PolygonRegion)
    • Box2DPolygonSprite

      public Box2DPolygonSprite​(com.badlogic.gdx.graphics.g2d.PolygonSprite sprite)
      See Also:
      PolygonSprite(PolygonSprite)
  • 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 Box2DPolygonSprites on the Body or Fixture that hold them in their user data in the given World
    • getZComparator

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

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

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

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

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

      public void draw​(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.physics.box2d.Body body)
      draws this Box2DPolygonSprite 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 Box2DPolygonSprite 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 PolygonSprite.width * PolygonSprite.height instead of the given size.
      The drawing position of the sprite is always the bottom left of the body or fixture.
      Parameters:
      batch - The Batch to draw on. Redirects to draw(PolygonSpriteBatch, float, float, float, float, float) if this is an instance of PolygonSpriteBatch.
      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
    • draw

      public void draw​(com.badlogic.gdx.graphics.g2d.PolygonSpriteBatch batch, float box2dX, float box2dY, float box2dWidth, float box2dHeight, float box2dRotation)
      See Also:
      draw(Batch, float, float, float, float, float)
    • 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
    • isAdjustToPolygon

      public boolean isAdjustToPolygon()
      Returns:
      the adjustToPolygon
    • setAdjustToPolygon

      public void setAdjustToPolygon​(boolean adjustToPolygon)
      Parameters:
      adjustToPolygon - the adjustToPolygon 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)