0 Favourites

How do I reset frame animation to 0 cycle

  • hey guys, first post here, thought I would ask something that is probably pretty obvious.

    Been trying to think of an elegant way to do the following: I have a sprite with multiple frames that I don't want to change until the user presses a button. Once the last frame in a cycle is up and the button is pressed again, I want the frame animation to reset to zero (basically, it's a character creation panel, so user dictates frame change).

    At the moment it stops at the last frame and doesn't cycle. I thought maybe changing the animation to a loop would bump it back to zero, but nope.

    So obviously it's easy to use set frame to go to the next frame when the button's pressed, and I was able to use a variable which counted the frames and reset it once it hit a certain number. Problem is, I want it set up so that I can change the number of frames in an animation without having to change individual variables, and have it still work.

    I tried comparing self.frameAnimation with self.frameAnimation +1 and resetting frame to zero if they were equal, but it didn't work for me. I guess it's comparing it to a number that doesn't exist in the cycle... realise my mistake there now as I typed it.

    I am really tired right now (had an early morning flight to catch), so I'm beginning to think I might be overlooking the obvious.

    Would love to hear what best solution to this would be. Something to look forward to in the morning

    Cheers

  • Set frame to (self.AnimationFrame +1) % self.AnimationFrameCount

    % is operator for Modulo

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Set frame to (self.AnimationFrame +1) % self.AnimationFrameCount

    % is operator for Modulo

    This works perfectly!

    Thank you.

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