How do I wait for animation to reach a specific frame

0 favourites
  • 6 posts
From the Asset Store
Add calm and a lounge vibe to your games with these 8 tracks
  • 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.

  • You can use condition sprite > compare frame:

    if object > animation frame = 10 {
    	object > set animation to "jump" (play from beginning)
    }
    [/code:32gsqy4l]
    Or you can use: (depends on your animation frames)
    [code:32gsqy4l]
    if object > on animation "sprint" finished {
    	object > set animation to "jump" (play from beginning)
    }
    [/code:32gsqy4l]
    
    EDIT: Maybe like this:
    [code:32gsqy4l]
    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)
    }
    [/code:32gsqy4l]
  • i HAVE ALREADY MADE TUTORIAL ON THIS

    How to Create Character's Multiple Movement on Single Animation

  • 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!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)