turn on and off with same button

This forum is currently in read-only mode.
  • i have a button (sprite) and when i click on it, another object is visible.

    when i click on this button again i want this object be invisible.

    so it will switching like on/off button.

    i believe it will be simple, but i can figure it out,

    thanks

  • Make clicking on the button toggle a Boolean.

    Check for the Boolean, if enabled, set the object invisible.

    Else, set the object visible.

    <img src="smileys/smiley4.gif" border="0" align="middle" />

    If you want to save events in the free version..

    Make two buttons, create one over the other, make the top one invisible by default.

    When you press the bottom button, it sets the top button to be visible and also makes the other object invisible.

    Pressing the top button would hide itself and make the other object visible.

  • For CC.

    Mouse on sprite clicked

    sprite2 set opacity to sprite2.opacity=100 ?0 :100

    Conditionals, very useful.

  • i tried to set up

    button is clicked and object is invisible, then object is visible

    then i made - button is clicked and object visible, -make object invisible

    but it does not work :(

  • i tried to set up

    button is clicked and object is invisible, then object is visible

    then i made - button is clicked and object visible, -make object invisible

    but it does not work :(

    For sure this won't work. Here is a description, why it can't work: Introduction into branching

    Meanwhile do so as Rory explained for C2, but instead of a Boolean you fake a boolean with a pv or global. Just set this variable to 1 - variable on every button click.

    Then use events like

    if variable = 1, make invisible

    if variable = 0, make visible

  • tulamide: thanks much, finally it works as i need!

    thanks!

  • Good point Tulamide.

    Global variable would work better.

    And I totally forgot he was working with CC. I was at the wrong side of the forum haha!

  • Tulamide "...fake a boolean with a pv or global. Just set this variable to 1 - variable on every button click..."

    How do you make it variable on every button click so it actually works?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • WizLore Not entirely sure what you mean there. What would you like to do in your game?

  • Just a toggle button...

    So far I made it as joxer first suggested... and made it work with a 'wait 0.05 seconds' to prevent it toggles back again...

    I know it's a messy way to do it, but I don't understand Tulamides answer.

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