Package net.dermetfan.gdx.graphics.g2d
Class AnimatedSprite
java.lang.Object
com.badlogic.gdx.graphics.g2d.TextureRegion
com.badlogic.gdx.graphics.g2d.Sprite
net.dermetfan.gdx.graphics.g2d.AnimatedSprite
public class AnimatedSprite
extends com.badlogic.gdx.graphics.g2d.Sprite
An
Usage:
AnimatedSprite
holds an Animation
and sets the Texture
of its super type Sprite
to the correct one according to the information in the Animation
.Usage:
Animation animation = new Animation(1 / 3f, frame1, frame2, frame3);
animation.setPlayMode(Animation.LOOP);
animatedSprite = new AnimatedSprite(animation);
Sprite's
draw methods:animatedSprite.draw(batch);
-
Constructor Summary
Constructors Constructor Description AnimatedSprite(com.badlogic.gdx.graphics.g2d.Animation<com.badlogic.gdx.graphics.g2d.TextureRegion> animation)
creates a newAnimatedSprite
with the givenAnimation
-
Method Summary
Modifier and Type Method Description void
draw(com.badlogic.gdx.graphics.g2d.Batch batch)
Draws
thisAnimatedSprite
.void
flipFrames(boolean flipX, boolean flipY)
flips all framesvoid
flipFrames(boolean flipX, boolean flipY, boolean set)
flips all framesvoid
flipFrames(float startTime, float endTime, boolean flipX, boolean flipY)
void
flipFrames(float startTime, float endTime, boolean flipX, boolean flipY, boolean set)
Flips all frames fromstartTime
toendTime
.com.badlogic.gdx.graphics.g2d.Animation
getAnimation()
float
getTime()
boolean
isAnimationFinished()
boolean
isAutoUpdate()
boolean
isCenterFrames()
boolean
isPlaying()
boolean
isUseFrameRegionSize()
void
pause()
setsplaying
to falsevoid
play()
setsplaying
to truevoid
setAnimation(com.badlogic.gdx.graphics.g2d.Animation animation)
void
setAutoUpdate(boolean autoUpdate)
void
setCenterFrames(boolean centerFrames)
void
setPlaying(boolean playing)
void
setTime(float time)
void
setUseFrameRegionSize(boolean useFrameRegionSize)
void
stop()
pauses and sets thetime
to 0void
update()
updates theAnimatedSprite
with the delta time fetched fromGdx.graphics.getDeltaTime()
void
update(float delta)
updates theAnimatedSprite
with the given delta timeMethods inherited from class com.badlogic.gdx.graphics.g2d.Sprite
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
-
Constructor Details
-
AnimatedSprite
public AnimatedSprite(com.badlogic.gdx.graphics.g2d.Animation<com.badlogic.gdx.graphics.g2d.TextureRegion> animation)creates a newAnimatedSprite
with the givenAnimation
- Parameters:
animation
- theanimation
to use
-
-
Method Details
-
update
public void update()updates theAnimatedSprite
with the delta time fetched fromGdx.graphics.getDeltaTime()
-
update
public void update(float delta)updates theAnimatedSprite
with the given delta time -
draw
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch)- Overrides:
draw
in classcom.badlogic.gdx.graphics.g2d.Sprite
-
flipFrames
public void flipFrames(boolean flipX, boolean flipY)flips all frames- See Also:
flipFrames(boolean, boolean, boolean)
-
flipFrames
public void flipFrames(boolean flipX, boolean flipY, boolean set)flips all frames -
flipFrames
public void flipFrames(float startTime, float endTime, boolean flipX, boolean flipY) -
flipFrames
public void flipFrames(float startTime, float endTime, boolean flipX, boolean flipY, boolean set)Flips all frames fromstartTime
toendTime
. Note the actual TextureRegions areflipped
, so if theanimation
contains a region more than once, those frames cannot be flipped differently at the same time. Also they will be flipped as often as they occur in the given time range.- Parameters:
startTime
- the animation state time of the first frame to flipendTime
- the animation state time of the last frame to flipset
- if the frames should be set toflipX
andflipY
instead of actually flipping them
-
play
public void play()setsplaying
to true -
pause
public void pause()setsplaying
to false -
stop
public void stop()pauses and sets thetime
to 0 -
setTime
public void setTime(float time)- Parameters:
time
- thetime
to go to
-
getTime
public float getTime()- Returns:
- the current
time
-
getAnimation
public com.badlogic.gdx.graphics.g2d.Animation getAnimation()- Returns:
- the
animation
-
setAnimation
public void setAnimation(com.badlogic.gdx.graphics.g2d.Animation animation)- Parameters:
animation
- theanimation
to set
-
isPlaying
public boolean isPlaying()- Returns:
- if this
AnimatedSprite
is playing
-
setPlaying
public void setPlaying(boolean playing)- Parameters:
playing
- if theAnimatedSprite
should be playing
-
isAnimationFinished
public boolean isAnimationFinished()- Returns:
- if the
animation
has finished playing
-
isAutoUpdate
public boolean isAutoUpdate()- Returns:
- the
autoUpdate
-
setAutoUpdate
public void setAutoUpdate(boolean autoUpdate)- Parameters:
autoUpdate
- theautoUpdate
to set
-
isUseFrameRegionSize
public boolean isUseFrameRegionSize()- Returns:
- the
useFrameRegionSize
-
setUseFrameRegionSize
public void setUseFrameRegionSize(boolean useFrameRegionSize)- Parameters:
useFrameRegionSize
- theuseFrameRegionSize
to set
-
isCenterFrames
public boolean isCenterFrames()- Returns:
- the
centerFrames
-
setCenterFrames
public void setCenterFrames(boolean centerFrames)- Parameters:
centerFrames
- thecenterFrames
to set
-