public class Box2DSprite
extends com.badlogic.gdx.graphics.g2d.Sprite
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.Modifier and Type | Field and Description |
---|---|
private boolean |
adjustHeight
if the width and height should be adjusted to those of the
Body or Fixture this Box2DSprite is attached to (true by default) |
private boolean |
adjustWidth
if the width and height should be adjusted to those of the
Body or Fixture this Box2DSprite is attached to (true by default) |
static net.dermetfan.utils.Function<java.lang.Object,Box2DSprite> |
defaultUserDataAccessor
the
userDataAccessor used by default |
private boolean |
useOriginX
if the origin of this
Box2DSprite should be used when it's drawn (false by default) |
private boolean |
useOriginY
if the origin of this
Box2DSprite should be used when it's drawn (false by default) |
private static net.dermetfan.utils.Function<java.lang.Object,Box2DSprite> |
userDataAccessor
the
Function used to get a Box2DSprite from the user data of a body or fixture |
private static com.badlogic.gdx.math.Vector2 |
vec2
for internal, temporary usage
|
private static java.util.Comparator<Box2DSprite> |
zComparator
|
private float |
zIndex
the z index for sorted drawing
|
Constructor and Description |
---|
Box2DSprite() |
Box2DSprite(com.badlogic.gdx.graphics.g2d.Sprite sprite) |
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) |
Box2DSprite(com.badlogic.gdx.graphics.g2d.TextureRegion region) |
Box2DSprite(com.badlogic.gdx.graphics.g2d.TextureRegion region,
int srcX,
int srcY,
int srcWidth,
int srcHeight) |
Modifier and Type | Method and Description |
---|---|
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 |
void |
draw(com.badlogic.gdx.graphics.g2d.Batch batch,
float box2dX,
float box2dY,
float box2dWidth,
float box2dHeight,
float box2dRotation)
Used internally.
|
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) |
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, setColor, setFlip, setOrigin, setOriginCenter, setPosition, setRegion, setRotation, setScale, setScale, setSize, setU, setU2, setV, setV2, setX, setY, translate, translateX, translateY
getRegionHeight, getRegionWidth, getRegionX, getRegionY, getTexture, getU, getU2, getV, getV2, isFlipX, isFlipY, setRegion, setRegion, setRegion, setRegion, setRegionHeight, setRegionWidth, setRegionX, setRegionY, setTexture, split, split
private float zIndex
private boolean adjustWidth
Body
or Fixture
this Box2DSprite
is attached to (true by default)private boolean adjustHeight
Body
or Fixture
this Box2DSprite
is attached to (true by default)private boolean useOriginX
Box2DSprite
should be used when it's drawn (false by default)private boolean useOriginY
Box2DSprite
should be used when it's drawn (false by default)private static final com.badlogic.gdx.math.Vector2 vec2
public static final net.dermetfan.utils.Function<java.lang.Object,Box2DSprite> defaultUserDataAccessor
userDataAccessor
used by defaultprivate static net.dermetfan.utils.Function<java.lang.Object,Box2DSprite> userDataAccessor
Function
used to get a Box2DSprite
from the user data of a body or fixtureprivate static java.util.Comparator<Box2DSprite> zComparator
public Box2DSprite()
Sprite.Sprite()
public Box2DSprite(com.badlogic.gdx.graphics.Texture texture, int srcWidth, int srcHeight)
Sprite.Sprite(Texture, int, int)
public Box2DSprite(com.badlogic.gdx.graphics.Texture texture, int srcX, int srcY, int srcWidth, int srcHeight)
Sprite.Sprite(Texture, int, int, int, int)
public Box2DSprite(com.badlogic.gdx.graphics.g2d.TextureRegion region, int srcX, int srcY, int srcWidth, int srcHeight)
Sprite.Sprite(TextureRegion, int, int, int, int)
public Box2DSprite(com.badlogic.gdx.graphics.Texture texture)
Sprite.Sprite(Texture)
public Box2DSprite(com.badlogic.gdx.graphics.g2d.TextureRegion region)
Sprite.Sprite(TextureRegion)
public Box2DSprite(com.badlogic.gdx.graphics.g2d.Sprite sprite)
Sprite.Sprite(Sprite)
public static void draw(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.physics.box2d.World world)
draw(Batch, World, boolean)
public static void draw(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.physics.box2d.World world, boolean sortByZ)
Box2DSprites
on the Body
or Fixture
that hold them in their user data in the given World
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.physics.box2d.Fixture fixture)
Box2DSprite
on the given Fixture
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, com.badlogic.gdx.physics.box2d.Body body)
Box2DSprite
on the given Body
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch, float box2dX, float box2dY, float box2dWidth, float box2dHeight, float box2dRotation)
Box2DSprite
in classic sprite coordinate system fashion with the given Box2D coordinates (combined with its own position, size and rotation).useOriginX/Y
is enabled, the origin
will be used instead of calculating an appropriate one for the given Box2D coordinates.adjustWidth/Height
is disabled, the size of the drawing area of the sprite will be Sprite.width
* Sprite.height
instead of the given size.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 fixturepublic float getZIndex()
zIndex
public void setZIndex(float zIndex)
zIndex
- the zIndex
to setpublic boolean isAdjustWidth()
adjustWidth
public void setAdjustWidth(boolean adjustWidth)
adjustWidth
- the adjustWidth
to setpublic boolean isAdjustHeight()
adjustHeight
public void setAdjustHeight(boolean adjustHeight)
adjustHeight
- the adjustHeight
to setpublic void setAdjustSize(boolean adjustSize)
adjustSize
- the adjustWidth
and adjustHeight
to setpublic boolean isUseOriginX()
useOriginX
public void setUseOriginX(boolean useOriginX)
useOriginX
- the useOriginX
to setpublic boolean isUseOriginY()
useOriginY
public void setUseOriginY(boolean useOriginY)
useOriginY
- the useOriginY
to setpublic void setUseOrigin(boolean useOrigin)
useOrigin
- the useOriginX
and useOriginY
to setpublic void setWidth(float width)
Sprite.setSize(float, float)
public void setHeight(float height)
Sprite.setSize(float, float)
public static java.util.Comparator<Box2DSprite> getZComparator()
zComparator
public static void setZComparator(java.util.Comparator<Box2DSprite> zComparator)
zComparator
- the zComparator
to setpublic static net.dermetfan.utils.Function<?,Box2DSprite> getUserDataAccessor()
userDataAccessor
public static void setUserDataAccessor(net.dermetfan.utils.Function<java.lang.Object,Box2DSprite> userDataAccessor)
userDataAccessor
- the userDataAccessor
to set