turn on and off with same button

For questions about using Classic.

Post » Wed Aug 01, 2012 5:29 pm

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
B
4
S
2
G
1
Posts: 143
Reputation: 1,211

Post » Wed Aug 01, 2012 5:38 pm

Make clicking on the button toggle a Boolean.
Check for the Boolean, if enabled, set the object invisible.
Else, set the object visible.



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.Rory2012-08-01 17:42:27
B
36
S
10
G
6
Posts: 948
Reputation: 11,101

Post » Wed Aug 01, 2012 6:12 pm

For CC.
Mouse on sprite clicked
>sprite2 set opacity to sprite2.opacity=100 ?0 :100

Conditionals, very useful.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Wed Aug 01, 2012 6:31 pm

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 :(
B
4
S
2
G
1
Posts: 143
Reputation: 1,211

Post » Wed Aug 01, 2012 10:29 pm

[QUOTE=joxer] 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 :([/QUOTE]
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
Image
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

Post » Thu Aug 02, 2012 8:53 am

tulamide: thanks much, finally it works as i need!
thanks!
B
4
S
2
G
1
Posts: 143
Reputation: 1,211

Post » Thu Aug 02, 2012 10:08 am

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!Rory2012-08-02 10:10:44
B
36
S
10
G
6
Posts: 948
Reputation: 11,101

Post » Thu May 02, 2013 9:48 pm

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?

B
9
S
4
G
1
Posts: 102
Reputation: 2,274

Post » Sat May 04, 2013 5:13 pm

@WizLore Not entirely sure what you mean there. What would you like to do in your game?
"Construct 4 lets YOU make advanced games! (maybe)" Construct Classic - Examples Kit
B
86
S
28
G
13
Posts: 2,092
Reputation: 15,009

Post » Sat May 04, 2013 7:50 pm

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.
B
9
S
4
G
1
Posts: 102
Reputation: 2,274

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: GameOverBeast and 1 guest