How do I wait for animation to reach a specific frame

Get help using Construct 2

Post » Mon Apr 17, 2017 7:53 am

Hello,

How can I wait for a sprite's animation to reach a specific frame before doing other things?

for example:
sprite idle animation plays and has 10 frame.
on click -> wait for animation to reach frame 10 or 0
do some other stuff
switch to jump animation

I've tried using 'wait for signal' but it doesn't make the event stop and wait, so it's doing the 'do some other stuff' and 'switch to jump animation' without waiting for the signal.

Any help will be appreciated.
Thanks.
B
8
S
2
Posts: 9
Reputation: 583

Post » Mon Apr 17, 2017 8:09 am

You can use condition sprite > compare frame:

Code: Select all
if object > animation frame = 10 {
   object > set animation to "jump" (play from beginning)
}

Or you can use: (depends on your animation frames)
Code: Select all
if object > on animation "sprint" finished {
   object > set animation to "jump" (play from beginning)
}


EDIT: Maybe like this:
Code: Select all
on start of layout {
   player.set animation to "idle"
}

on object player clicked {
   player.set animation to "sprint" (play from beginning)

if player.animation name == "sprint" AND player.animation frame == 10 {
   player.set animation to "jump" (play from beginning)
}

OR

player > on animation "sprint" finished {
   object > set animation to "jump" (play from beginning)
}
B
33
S
10
G
2
Posts: 46
Reputation: 3,063

Post » Mon Apr 17, 2017 11:54 am

Image
B
68
S
40
G
48
Posts: 680
Reputation: 34,066

Post » Mon Apr 17, 2017 1:09 pm

Thank you guys!
In the end I solved the problem with an un-elegant solution by using "wait" actions, but I learned some new things from your comments! :)
B
8
S
2
Posts: 9
Reputation: 583

Post » Mon Apr 17, 2017 1:52 pm

@orinab

I am not a fan of wait actions. Because while you are waiting, you might need to change what should happen next.

I made a quick sample of how I would "schedule" a next animation to play. There are two types of animations - looping and non-looping. You always want to change animations at the end, but looping animations don't trigger an On Finished event so you have to look for the first (or last) frame. I chose to look for the first frame because various looping animations could be different lengths. For animations that don't loop, you just need an On Finished event, and if no animation is scheduled while a non-looping animation is playing, then when it finishes, go back to idle.

I figured that there may be situations where you just can't wait for the current animation to finish, so I made one that will always start immediately (the Die animation).

You can get my sample here: http://www.rieperts.com/games/forum/AnimationSchedule.capx

my sample doesn't queue up multiple animations... if the walk animation is playing and you quickly press jump and attack, it will switch directly to attack (or whatever the "NextAnimation" is set to when the current one ends). But if you want a queue, that wouldn't be hard to do.

I was just discussing this with my son, and he reminded me that Spriter has built in animation blending - so you may want to check that out too.
Last edited by AllanR on Mon Apr 17, 2017 2:04 pm, edited 1 time in total.
B
98
S
34
G
20
Posts: 438
Reputation: 17,825

Post » Mon Apr 17, 2017 2:00 pm

AllanR wrote:@orinab

I am not a fan of wait actions. Because while you are waiting, you might need to change what should happen next.



Heh, was just about to say the same thing, then noticed you'd posted: unless absolutely necessary I'd avoid waits, they have a habit of creating all sorts of problems unless used very carefully. If there's an alternative I'd use it - any of the other solutions mentioned here would be preferable.
B
20
S
9
G
4
Posts: 473
Reputation: 4,260


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests