How do I loop clicking through animation frames?

1 favourites
  • 7 posts
From the Asset Store
SynthWave Loop Pack includes 68 seamless loops, founded on 11 original melodies.
  • Hello friends, this is the method I have devised to click endlessly on a sprite and cycle through the animation frames in order (not randomly), looping back to the beginning after the last frame. I'm just wondering if this is the most commmon, "correct" way to achieve this. It seems to work well and is simple enough.

    Many thanks for any input.

    Tagged:

  • You don't need to use a global variable, the object has object.animationframecount expression

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I'm not sure what that would look like. I've tried this before, using the object's expression, but it doesn't work. Thanks for the feedback.

  • Yeah the reason that doesn't work as expected is because framecount is always 1 higher than the final frame, because frames start at 0. The logic to make it work would be something like, on sprite clicked, if current frame not equal to object.animframecount-1 then add 1 to frame else set frame to 0. Which is effectively saying, on object clicked if you are not on the last frame then go to next frame else go to the first frame.

  • That works, thanks, it's good to understand how to do it both ways. Thanks for the replies.

  • You can also use sprite - set animation frame to 'self.animationframe=self.animationframecount-1?0:self.animationframe+1'.

    This is called a conditional expression and let's you do if?then:else in a single line.

  • Thanks for this. I would like to start doing more of this. Get closer to real programming. This is helpful.

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