Package net.dermetfan.gdx.graphics.g2d
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
theuserDataAccessor
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 thisBox2DSprite
on the givenBody
void
draw(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.physics.box2d.Fixture fixture)
draws thisBox2DSprite
on the givenFixture
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 theBox2DSprites
on theBody
orFixture
that hold them in their user data in the givenWorld
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> defaultUserDataAccessortheuserDataAccessor
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 theBox2DSprites
on theBody
orFixture
that hold them in their user data in the givenWorld
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.physics.box2d.Fixture fixture)draws thisBox2DSprite
on the givenFixture
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.physics.box2d.Body body)draws thisBox2DSprite
on the givenBody
-
draw
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, float box2dX, float box2dY, float box2dWidth, float box2dHeight, float box2dRotation)Used internally. Draws thisBox2DSprite
in classic sprite coordinate system fashion with the given Box2D coordinates (combined with its own position, size and rotation).
IfuseOriginX/Y
is enabled, theorigin
will be used instead of calculating an appropriate one for the given Box2D coordinates.
IfadjustWidth/Height
is disabled, the size of the drawing area of the sprite will beSprite.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 fixturebox2dY
- the y coordinate (center) of the body or fixturebox2dWidth
- the width of the body or fixturebox2dHeight
- the height of the body or fixturebox2dRotation
- the rotation of the body or fixture
-
getZIndex
public float getZIndex()- Returns:
- the
zIndex
-
setZIndex
public void setZIndex(float zIndex)- Parameters:
zIndex
- thezIndex
to set
-
isAdjustWidth
public boolean isAdjustWidth()- Returns:
- the
adjustWidth
-
setAdjustWidth
public void setAdjustWidth(boolean adjustWidth)- Parameters:
adjustWidth
- theadjustWidth
to set
-
isAdjustHeight
public boolean isAdjustHeight()- Returns:
- the
adjustHeight
-
setAdjustHeight
public void setAdjustHeight(boolean adjustHeight)- Parameters:
adjustHeight
- theadjustHeight
to set
-
setAdjustSize
public void setAdjustSize(boolean adjustSize)- Parameters:
adjustSize
- theadjustWidth
andadjustHeight
to set
-
isUseOriginX
public boolean isUseOriginX()- Returns:
- the
useOriginX
-
setUseOriginX
public void setUseOriginX(boolean useOriginX)- Parameters:
useOriginX
- theuseOriginX
to set
-
isUseOriginY
public boolean isUseOriginY()- Returns:
- the
useOriginY
-
setUseOriginY
public void setUseOriginY(boolean useOriginY)- Parameters:
useOriginY
- theuseOriginY
to set
-
setUseOrigin
public void setUseOrigin(boolean useOrigin)- Parameters:
useOrigin
- theuseOriginX
anduseOriginY
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
- Returns:
- the
zComparator
-
setZComparator
- Parameters:
zComparator
- thezComparator
to set
-
getUserDataAccessor
- Returns:
- the
userDataAccessor
-
setUserDataAccessor
public static void setUserDataAccessor(net.dermetfan.utils.Function<java.lang.Object,Box2DSprite> userDataAccessor)- Parameters:
userDataAccessor
- theuserDataAccessor
to set
-