How do I make frames change when I click?

Get help using Construct 2

Post » Mon May 01, 2017 3:01 pm

Hi everyone!
I'm new to Construct 2 and it's fascinating!
However, I have a problem. when I click , i want the frame of the object changes from frame 0 to frame 1; then I click again, the frame changes from 1 to 2, click again, it changes from 2 to 0, then the frame changes from 0 to 1 when I click again.....
Thank you so much!!
Posts: 3
Reputation: 231

Post » Mon May 01, 2017 3:35 pm

onClick on Object (Sprite)

if Sprite.AnimationFrame = (Sprite.AnimationFrameCount-1) then
set frame to 0
set frame to self.animationframe + 1

*The -1 is because frame numbers start at 0
Posts: 1,224
Reputation: 17,192

Post » Mon May 01, 2017 3:45 pm

Hi @ToquocVN, Glad to hear you're enjoying C2 - it's a great tool :)

There are a few ways to achieve what you want; I've included two in this demo: ... .capx?dl=0

Sprite A is using a typical condition and actions setup, checking the current frame in one condition and then changing the frame in the subsequent action - one problem with this is that you need to include the "Else" condition, which can sometimes cause problems if you have multiple instances of the same sprite.

A way around this is to use the question mark conditional operator within the action; you use it in this format: (condition to check)?(If true do this):(If false do this) - Sprite B is using this technique on event 4 to check its current fame - if its frame is less than 2 it adds 1 otherwise it sets it to 0.

This is handy as it can save you including a bunch of nested conditions and gets around problems with the "Else" condition.

One more thing: make sure that the animation speed for your sprites are set to zero, or use the "stop animation" action, otherwise by default it is set to run to the final frame.

Hope that helps :)
Last edited by mekonbekon on Mon May 01, 2017 6:14 pm, edited 1 time in total.
Posts: 515
Reputation: 4,472

Post » Mon May 01, 2017 5:11 pm

Thank you so much for your help! It's very easy for me to understand!
I didn't think you guys are so kind :D
Posts: 3
Reputation: 231

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 4 guests