Example usage for com.badlogic.gdx.graphics.g2d Animation isAnimationFinished

List of usage examples for com.badlogic.gdx.graphics.g2d Animation isAnimationFinished

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g2d Animation isAnimationFinished.

Prototype

public boolean isAnimationFinished(float stateTime) 

Source Link

Document

Whether the animation would be finished if played without looping (PlayMode#NORMAL), given the state time.

Usage

From source file:com.dongbat.invasion.system.SpriteAnimationRenderSystem.java

@Override
protected void process(Entity entity) {
    SpriteAnimation spriteAnimation = sa.get(entity);
    DisplayPosition displayPosition = dp.get(entity);
    String current = spriteAnimation.getCurrent();
    if (current == null) {
        return;//  ww  w .j a  v a  2s  .c om
    }

    Animation animation = spriteAnimation.getAnimation(current);
    if (animation == null) {
        return;
    }

    long startTime = spriteAnimation.getStartTime();
    if (startTime == -1) {
        return;
    }

    float stateTime = TimeUtil.millisToSeconds(TimeUtil.getGameTimeSince(startTime));

    if (animation.isAnimationFinished(stateTime) && !spriteAnimation.isLooping()) {
        SpriteAnimation.AnimationFinishedCallback callback = spriteAnimation.getCallback();
        if (callback != null) {
            callback.finished(entity);
        }
        return;
    }

    TextureRegion frame = animation.getKeyFrame(stateTime, spriteAnimation.isLooping());
    // TODO: camera
    batch.draw(frame, displayPosition.getX() - frame.getRegionWidth() / 2f,
            displayPosition.getY() - frame.getRegionHeight() / 2f);
    batch.setProjectionMatrix(RenderCameraUtil.getCamera().combined);
}

From source file:gui.AnimEffects.java

public boolean isAnimationFinished(com.badlogic.gdx.graphics.g2d.Animation animation) {
    return animation.isAnimationFinished(stateTime);
}