Possibly stupid animation question (read with care)



I am trying to play an animation on an actor and then when it’s finished loop another one, but if i loop an animation the one that was supposed to play before it, doesn’t. Is there a way (not including intervals) to make the actor wait untill the first animation has finished playing and only then start to loop the other one?


You can monitor the currently played frame of the 1st anim. Once it reaches the end frame,

if myactor.getCurrentFrame()==myactor.getNumFrames()

then you start looping the 2nd one.
Well, I’m not sure it will work if your anim start frame is NOT frame 1.
Read the reference of the Actor class for controlling your anim.

You can also do a taskMgr.doMethodLater() to start the second animation after the appropriate amount of time has elapsed to play the first animation.

But, really, intervals are the way you’re supposed to do this sort of thing.


The thing is I’m using a FSM to change to different states
but if i just have something like: myactor.play(‘anim1’) after playing the animation it doesn’t exit the current state untill you call another state or cleanup (so it just sits there doing nothing which is not the result i’m after:) ) but I can’t call another state and neither start looping another animation sice i don’t know when the first one is finished
the myactor.getCurrentFrame() seems like a good option but lucky me it allways returns 0.
myactor.getNumFrames() is working, precisely showing the total number of frames for my animation but since I can’t find out what’s the current frame i can’t do it that way

15 minutes later :smiley:

I’m having a major breakthrough with actor intervals :stuck_out_tongue: but I’d like to know if there is a better way if possible :smiley: or if there is a way to loop an interval indefinetely instead of just for the set duration


You can actually loop an interval, read these :
Thus, basically this must work :

myActorInterval1 = myactor.actorInterval("Animation1", loop=0)
myActorInterval2 = myactor.actorInterval("Animation2", loop=1)

basically it should work :smiley: but unfortunately it doesn’t

doing this

myActorInterval2 = myactor.actorInterval("Animation2", loop=1)

plays the interval only once :unamused:

instead you have to do this:

myActorInterval2 = myactor.actorInterval("Animation2", loop=1, duration= <seconds>)

only then will it loop for the finite amount of time that you specified
this I wanted to know if it can be avoided to make it loop for ever :smiley:


Looks like 1 more bug :open_mouth: to me.
Have you tried looping the sequence instead of starting it ?

yes looping the sequence works but might not be the best choice since if you have 1 interval that you need to play once and another interval that you need to loop the first interval will play once, the second interval will play once then start over doing the same thing
but on the other hand if you have a sequence with just 1 interval that you need to loop forever mysequence.loop() works well

Then it must be a bug.

It’s not a bug: intervals, by their nature, are finite (and specific) in duration. What would it mean to loop an interval within another interval? For how long should it loop? Forever? What if you had put another animation in the sequence following the looping animation? When would it ever stop looping and play the next item in the sequence?

Intervals don’t loop internally. If, however, you wanted to play animation 1 say, exactly 3 times, and then play animation 2, you would do it like this:

i = Sequence(ActorInterval(a, 'anim1', duration = a.getDuration('anim1') * 3,
             ActorInterval(a, 'anim2'))

Which “loops” animation 1 over the total specified duration–basically stamping out a number of copies of animation 1 into the interval. But you can’t loop an animation indefinitely through an interval.

It sounds like you’re asking for animation 1 to play once, and then afterwards the actor should loop animation 2 indefinitely, until it receives other instructions. You can do this, with an interval something like this:

i = Sequence(ActorInterval(a, 'anim1'),
             Func(a.loop, 'anim2'))

The point here is that the actual looping of animation 2 isn’t included within the interval; but the last thing the interval does is tell the Actor to start looping its own animation.