After reviewing Runtime docs I see that you can add animations via state.addAnimation API. So this can be done after some event or state update such mouse click, key press etc . How do stop the animation?

I have a track 0 'walk' animation, and a track 1 'shoot weapon' animation. So on a key press, I would call something like:

TrackEntry te = state.addAnimation(...., "shoot", ....)

And when key is no longer pressed:

state.setEmptyAnimation(te.getTrackIndex(), 0f);

Is this the correct way?
  • 記事: 8


Yes, calling setEmptyAnimation() is one possible way to stop an already playing looping animation.

What you could also consider is finishing an already playing shoot animation before stopping. This can be done by calling addEmptyAnimation() with a delay of 0:
addEmptyAnimation(trackIndex, 0.2f, 0);
Another way would be to register to the animationState.complete or trackEntry.complete event and handle each loop completion. This is a more complicated way though and makes more sense if you need to adjust your gamestate as well upon completion of a loop.

  • 記事: 3479

Return to Runtimes