A built-in way to control animation looping, Finally!

Hey guys!

“How to stop animation from looping?”

This question has been asked over and over on the forum and we were suggesting adding a CallMethod tween at the end to remove action when the animation is finished.

Now we have a built-in way for this as well. AnimLayer now supports enabling/disabling looping. You can specify if the action should loop or not when setting the current action:

this feature is available on the master branch and there is a high chance will be included in the v3.6 release.

There are a few more other enhancements as well.

  • Option to enable/disable animation mask propagation to child actions.
  • Option to control max transition weight. For example useful for controlling smooth animation transition when an animation is removed from an upper layer.
  • AnimLayer can now also keep the action name, so one can easily look up the currently playing action name in a specific layer.

If you are interested you can take a look at this PR:

12 Likes

I forgot to mention that if you want to loop animation for a specific duration or specific count there we have a new Loop tween added as well in a separate PR. You can use

Tweens.loopDuration(desiredDuration, delegate) 

or

 Tweens.loopCount(desiredCount, delegate)
2 Likes

Does this support the old loop modes by any chance? LoopMode (jMonkeyEngine3)

Mainly the CYCLE and LOOP.

1 Like

Only Loop and DontLoop are supported. Cycle is not supported.

For the cycle you can do it with the power of tween API:

Tweens.sequence(action, inverse(action));

Edit:

I think it is a good idea to add a Tweens.cycle() as well :slight_smile:

4 Likes

I would absolutely love this!

1 Like

I will submit a PR soon :slight_smile:

1 Like

Here you go

5 Likes

This is great news, I need looping desperately. When is 3.6 due?

And what means are there to respond to a action finished playing? I have a guy here who needs to resume his businness after having hit the other guy.

I do not know. No one is associated with the 3.6 release management yet. You can still build the engine from the source if you want to try new features. Let me know if you have an issue building from the source.

You can use CallMethod tween to respond to action finishing.

Something like this:

animComposer.actionSequence(hitAction, Tweens.callMethod("onHitDone"));
2 Likes

Building the engine myself is too complex for me, for now. I have workaround that works for the mock up phase I am in now:

Start the animation:

Set a variable 'lastTime'  to -1 and start the action you do not want to loop.

Every loop:

if lastTime>composer.getTime()
   animation is ready. Do what you need to do now.
else
   lastTime=composer.getTime()

another thing: the documentation is not clear about this, but it looks like getTime() gives a float between 0 and 1. I would have expected it to give the actual time.

And one more question: how do I freeze an action?

No, it should return the actual animation time in seconds. Probably your animation is shorter than 1 second.

simple way is to use Action.setSpeed(0)

1 Like

Note: building the SDK is tricky but building the engine is pretty straight forward if you already have git, jdk, etc. installed:

git clone https://github.com/jMonkeyEngine/jmonkeyengine.git
cd jmonkeyengine.git
gradlew install

…or if you are not using gradle/maven for your builds and need the actual jars, I think “gradlew dist” still works.

1 Like

That works! tnx

2 Likes