How do I reset frame animation to 0 cycle

Get help using Construct 2

Post » Sun Mar 26, 2017 9:45 am

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 :P

Cheers
B
15
S
4
Posts: 38
Reputation: 951

Post » Sun Mar 26, 2017 10:10 am

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

% is operator for Modulo
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Mon Mar 27, 2017 1:33 am

99Instances2Go wrote:Set frame to (self.AnimationFrame +1) % self.AnimationFrameCount

% is operator for Modulo


This works perfectly!

Thank you.
B
15
S
4
Posts: 38
Reputation: 951


Return to How do I....?

Who is online

Users browsing this forum: Ashley and 20 guests