2017-10-27 3 views
0

Ich verwende eine Animation mit 6 Frames in meinem Spiel für eine Veranstaltung. Es hat eine feste Reihenfolge, um gespielt zu werden.Wie ein Animationsrahmen für einmal jedes Mal zu spielen? -LibGdx

Array<TextureAtlas.AtlasRegion> anim=new Array<TextureAtlas.AtlasRegion>(); 
anim = game.playAtlas.findRegions(RegionNames.FEATHER_ANIMATION); 
TextureRegion[] ftr = {anim.get(0),anim.get(1),anim.get(2),anim.get(3),anim.get(4),anim.get(5)}; 

featherAnimation = new Animation(0.1f,ftr); 
featherAnimation.setPlayMode(PlayMode.NORMAL); 

Ich möchte nur einmal diese Animation laufen (das bedeutet, sollte es 0. Rahmen letzten Frame spielen und dann aufhören sollte), wenn eine bestimmte boolean wahr ist.

Nach dem Abspielen des letzten Frames, sollte es aufhören und den Boolean auch falsch machen.

Wie dies tat ich

if (featherBool && egg.isEggAtNest()) { 
    featherTexture = featherAnimation.getKeyFrame(animationTime, true); 
    batch.draw(featherTexture, egg.getX() - featherTexture.getRegionWidth()/2, fx.getY()); 
    featherBool = false; 
} 

Aber dies zu erreichen, ist nicht das, was ich will.

Die Frames sind nicht in der Reihenfolge, die ich angegeben habe. Auch, wie kann ich die Animation stoppen, sobald es spielt 0 bis 5 th Frame?

Antwort

0

Verwendung auf diese Weise:

if (featherBool) { 
    animationTime+=.01f; 
    featherTexture = featherAnimation.getKeyFrame(animationTime); // <--looping not required so remove second argument 
    batch.draw(featherTexture, egg.getX() - featherTexture.getRegionWidth()/2, fx.getY()); 
    if(featherAnimation.isAnimationFinished(animationTime)) 
     featherBool = false; 
} 

Anruf showAnimation() Methode

private void showAnimation(){ 

    featherBool=true; 
    animationTime=0; 
} 
0

Verwenden Sie Ihren animationTime Wert für andere Animationen? Wenn ja, sollten Sie ihn auf 0 setzen, bevor Sie featherAnimation abspielen.

if (somethingToRunfeatherAnimation) { 
    animationTime = 0; 
    featherBool = true; 
} 

Auch dieser Schnipsel nur einmal ausgeführt werden, da Sie featherBool = false sofort eingestellt.

if (featherBool && egg.isEggAtNest()) { 
    featherTexture = featherAnimation.getKeyFrame(animationTime, true); 
    batch.draw(featherTexture, egg.getX() - featherTexture.getRegionWidth()/2, fx.getY()); 
    featherBool = false; 
} 

es wie folgt verwendet:

if (featherBool && egg.isEggAtNest() && !featherAnimation.isAnimationFinished(animationTime) { 
    featherTexture = featherAnimation.getKeyFrame(animationTime); // deleted looping 
    batch.draw(featherTexture, egg.getX() - featherTexture.getRegionWidth()/2, fx.getY()); 
} 
-1

Der Render-Code aufgerufen wird nur einmal

if (featherBool && egg.isEggAtNest()) { 
    featherTexture = featherAnimation.getKeyFrame(animationTime, true); 
    batch.draw(featherTexture, egg.getX() - featherTexture.getRegionWidth()/2, fx.getY()); 
    featherBool = false; /// The render code is called only once 
} 

Sie müssen auch die Zeit erhöhen.

stateTime += Gdx.graphics.getDeltaTime(); 

Bevor Sie den featherBool Wert falsch ist, müssen Sie den Endpunkt Animation platzieren

if(yourAnimation.isAnimationFinished(stateTime)) 
     featherBool = false; 
Verwandte Themen