Toggle Frames with ONE button

0 favourites
  • 9 posts
From the Asset Store
J-BoB Game Button Sound Pack comes with 300 high-quality sound effects
  • Hello,

    I have a character that I want to have PUNCH with his fists

    when the SPACE key is pressed...

    However, I would like to have this character TOGGLE back

    and forth between LEFT and RIGHT PUNCHES with each SPACE key



    SPACE key Pressed = Select Frame0 (LEFT PUNCH)

    SPACE key Pressed = Select Frame1 (RIGHT PUNCH)

    I am having trouble testing a boolean state.

    I can create a Global variable or Instance Variable (BOOLEAN)

    but I can't find a method to TEST the current state.

    If PunchLR = True then...


    If PunchLR = False then...

    Any ideas to get my DUDE to TOGGLE PUNCHES with just ONE SPACE key press???

  • How about this?

    Create a global variable called "spacekey" or something like that. Then create an event: "on Space Key pressed" -> Set variable "spacekey" to "1-spacekey" (without quotes; and where "spacekey" is the name of your global variable; on the event sheet it should look like this: 1-spacekey.

    Now create 2 new events for "Compare variable spacekey"...

    on the first one: "spacekey" = 0 -> Set animation to Frame0

    on the second one: "spacekey" = 1 -> Set animation to Frame1

    Please let me know if this works out for you.

  • Thank you for the advice...

    It did work, randomly though..

    Normally, I would just create a global boolean variable

    and add..

    if boolean = true then setframe to 1

    if boolean - false then setframe to 0

    and then toggle the boolean variable...


    Not possible???

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Bascially,


    Test the boolean variable..

    If true, then set frame to 1

    if false, then set the frame to 0

    then toggle the boolean variable state for the next keypress

  • Create your sprite with your boolean, let's say "leftPunch", then setup your events like so...

    On key pressed |

        Is boolean instance variable set ('leftPunch') | - set frame 0

                                                                             - toggle boolean ('leftPunch')

        Else | - set frame 1

                 - toggle boolean ('leftPunch')

    That should get you started. "Is boolean instance variable set" only tests for true however, if there are moments when you specifically need to test for false, simply right click the condition and select "invert" this makes it a NOT condition. So basically, "Is boolean instance variable set (inverted)" = "If boolean is NOT true". Hope this helps :) Merry Christmas!

  • Hey Brent,

    Thanks for the advice..

    I created a BOOLEAN Instance variable for this sprite which has 2 frames

    LEFT=0 and RIGHT=1 for LEFT RIGHT punches.

    I have a ON KEY DOWN event..

    In that event, I am not seeing an option for testing the BOOLEAN instance variable as you suggested.

    The menu choices are as follows..


    The SET VALUE never seems to SEE my instance variable on the list.

    My guess is because it is not meant for Boolean values.

    I have been puzzled by the menu options available at times.

    Under what situation does the options for

    "If then else" appear???

  • Sounds like you're looking at actions. The option for comparing booleans is a condition.

    For else, right-click the event and go to the 'Add' sub-menu and the last option is 'Add else'. Or the shortcut is select the event and press 'X'.

    <img src="" border="0" />

  • Hey Ramones,

    THANK YOU sooo MUCH...

    I'm new to C2, less than 2 weeks, and I've been trying to find the conditional logic menu system.

    I "right-click" and your right, there they are..


    Thanks again... :)

  • You could use an integer too to keep track of which animation is playing.

    On key pressed

       Set animation to instanceInt

       Set instanceInt to (instanceInt + 1) % 2

    A bit tidier and permits you to add a third or even more animations to your attack sequence !

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