How do I make frames change when I click?

0 favourites
  • 4 posts
From the Asset Store
High quality sound effect pack, in the following categories: Simple, negative, pozitive
  • 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!!

  • Try Construct 3

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

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

  • Hi ToquocVN, Glad to hear you're enjoying C2 - it's a great tool <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

    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 <img src="{SMILIES_PATH}/icon_e_smile.gif" alt=":)" title="Smile">

  • Thank you so much for your help! It's very easy for me to understand!

    I didn't think you guys are so kind

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