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 newAnimatedSpritewith the givenAnimation -
Method Summary
Modifier and Type Method Description voiddraw(com.badlogic.gdx.graphics.g2d.Batch batch)DrawsthisAnimatedSprite.voidflipFrames(boolean flipX, boolean flipY)flips all framesvoidflipFrames(boolean flipX, boolean flipY, boolean set)flips all framesvoidflipFrames(float startTime, float endTime, boolean flipX, boolean flipY)voidflipFrames(float startTime, float endTime, boolean flipX, boolean flipY, boolean set)Flips all frames fromstartTimetoendTime.com.badlogic.gdx.graphics.g2d.AnimationgetAnimation()floatgetTime()booleanisAnimationFinished()booleanisAutoUpdate()booleanisCenterFrames()booleanisPlaying()booleanisUseFrameRegionSize()voidpause()setsplayingto falsevoidplay()setsplayingto truevoidsetAnimation(com.badlogic.gdx.graphics.g2d.Animation animation)voidsetAutoUpdate(boolean autoUpdate)voidsetCenterFrames(boolean centerFrames)voidsetPlaying(boolean playing)voidsetTime(float time)voidsetUseFrameRegionSize(boolean useFrameRegionSize)voidstop()pauses and sets thetimeto 0voidupdate()updates theAnimatedSpritewith the delta time fetched fromGdx.graphics.getDeltaTime()voidupdate(float delta)updates theAnimatedSpritewith 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, translateYMethods 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, splitMethods 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 newAnimatedSpritewith the givenAnimation- Parameters:
animation- theanimationto use
-
-
Method Details
-
update
public void update()updates theAnimatedSpritewith the delta time fetched fromGdx.graphics.getDeltaTime() -
update
public void update(float delta)updates theAnimatedSpritewith the given delta time -
draw
public void draw(com.badlogic.gdx.graphics.g2d.Batch batch)- Overrides:
drawin 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 fromstartTimetoendTime. Note the actual TextureRegions areflipped, so if theanimationcontains 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 toflipXandflipYinstead of actually flipping them
-
play
public void play()setsplayingto true -
pause
public void pause()setsplayingto false -
stop
public void stop()pauses and sets thetimeto 0 -
setTime
public void setTime(float time)- Parameters:
time- thetimeto 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- theanimationto set
-
isPlaying
public boolean isPlaying()- Returns:
- if this
AnimatedSpriteis playing
-
setPlaying
public void setPlaying(boolean playing)- Parameters:
playing- if theAnimatedSpriteshould be playing
-
isAnimationFinished
public boolean isAnimationFinished()- Returns:
- if the
animationhas finished playing
-
isAutoUpdate
public boolean isAutoUpdate()- Returns:
- the
autoUpdate
-
setAutoUpdate
public void setAutoUpdate(boolean autoUpdate)- Parameters:
autoUpdate- theautoUpdateto set
-
isUseFrameRegionSize
public boolean isUseFrameRegionSize()- Returns:
- the
useFrameRegionSize
-
setUseFrameRegionSize
public void setUseFrameRegionSize(boolean useFrameRegionSize)- Parameters:
useFrameRegionSize- theuseFrameRegionSizeto set
-
isCenterFrames
public boolean isCenterFrames()- Returns:
- the
centerFrames
-
setCenterFrames
public void setCenterFrames(boolean centerFrames)- Parameters:
centerFrames- thecenterFramesto set
-