How do I make a (settings) toggle switch button?

Get help using Construct 2

Post » Fri Aug 07, 2015 1:50 am

Hello. I already made a toggle switch button: https://gyazo.com/d02c0eb9cf1a5700850019549be49f9d (consists of 5 sprites; settings button, blue bar, info, sound & music).

I've managed to make the blue bar and the other items pop-up after the settings button is clicked.
However, I am struggling at making it disappear once you re-click again.

I've tried and didn't work:
1. Making a global variable (Settings_Clicked) with default value of 0. When the settings button is clicked, the value changes to 1. Afterwards, if the value is 1 and there's a click on the settings button then the rest of the items will be invisible.
2. Make 2 settings buttons sprites. The primary one (when not clicked) would be visible until it's clicked. Once it's clicked, it will become invisible and the secondary button will appear among with the rest of the items. Once the secondary button is clicked, the button itself and the popup will be hidden and the primary button will be visible again.

Please advice. I switched from native iOS Swift development and Stencyl to Construct 2 and I am having a bit of hard time understanding its programming mechanics.
B
9
S
2
Posts: 30
Reputation: 651

Post » Fri Aug 07, 2015 8:21 am

Many ways to do this..

One way is to give the settings button an instance variable boolean "active"

on settings clicked
> toggle boolean variable
-- settings is boolean
> set sprites visible
-- settings is not boolean
> set sprites invisible

Also using an else statement could be used for this and many other things..

If instead of setting visible you create and destroy the rest of the sprites, you could prevent the possibility of clicking them, instead of having to add extra conditions for that..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Aug 07, 2015 10:00 am

IncentiveGames wrote:Hello. I already made a toggle switch button: https://gyazo.com/d02c0eb9cf1a5700850019549be49f9d (consists of 5 sprites; settings button, blue bar, info, sound & music).

I've managed to make the blue bar and the other items pop-up after the settings button is clicked.
However, I am struggling at making it disappear once you re-click again.

I've tried and didn't work:
1. Making a global variable (Settings_Clicked) with default value of 0. When the settings button is clicked, the value changes to 1. Afterwards, if the value is 1 and there's a click on the settings button then the rest of the items will be invisible.
2. Make 2 settings buttons sprites. The primary one (when not clicked) would be visible until it's clicked. Once it's clicked, it will become invisible and the secondary button will appear among with the rest of the items. Once the secondary button is clicked, the button itself and the popup will be hidden and the primary button will be visible again.

Please advice. I switched from native iOS Swift development and Stencyl to Construct 2 and I am having a bit of hard time understanding its programming mechanics.


If you attach a capx example I can implement the rest for you ;=)
Image Image iTunes: Match3 | Google Play: Match3
B
102
S
37
G
31
Posts: 1,162
Reputation: 28,879

Post » Fri Aug 07, 2015 10:59 am

I prefere to make toggles like that:

Image
B
9
S
1
Posts: 50
Reputation: 650

Post » Fri Aug 07, 2015 12:32 pm

vendara wrote:I prefere to make toggles like that:

Image


If you use that, why not just use:

on left button clicked
> set Toggle = 1-Toggle
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Aug 07, 2015 1:35 pm

LittleStain wrote:
vendara wrote:I prefere to make toggles like that:

Image


If you use that, why not just use:

on left button clicked
> set Toggle = 1-Toggle


Didn't thought about that, it's even more simple. Thanks!
B
9
S
1
Posts: 50
Reputation: 650

Post » Fri Aug 07, 2015 4:42 pm

Hello everyone. At the end of the day, I used a combination of the recommended solutions (thanks guys) and it worked out.

Settings_Switch is a global variable

Here's the preview:
https://gyazo.com/061fef7473d18dbf2cf92866be288e1b
B
9
S
2
Posts: 30
Reputation: 651

Post » Fri Aug 07, 2015 4:55 pm

IncentiveGames wrote:Hello everyone. At the end of the day, I used a combination of the recommended solutions (thanks guys) and it worked out.

Settings_Switch is a global variable

Here's the preview:
https://gyazo.com/061fef7473d18dbf2cf92866be288e1b


Yep, that will work..

You could remove the Settings_Switch > 1 event and make the action of the first event

system set Settings_Switch = 1 - Settings_Switch

It's one event less..

Also I'd make the third an fourth event subevents of the top-event, because they only have to be checked at the time of the toggle..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Aug 07, 2015 5:54 pm

LittleStain wrote:
IncentiveGames wrote:Hello everyone. At the end of the day, I used a combination of the recommended solutions (thanks guys) and it worked out.

Settings_Switch is a global variable

Here's the preview:
https://gyazo.com/061fef7473d18dbf2cf92866be288e1b


Yep, that will work..

You could remove the Settings_Switch > 1 event and make the action of the first event

system set Settings_Switch = 1 - Settings_Switch

It's one event less..

Also I'd make the third an fourth event subevents of the top-event, because they only have to be checked at the time of the toggle..


Thank you for the advice. Still learning Construct 2 event sheet feature and your help is outstandingly great and very much appreciated.
B
9
S
2
Posts: 30
Reputation: 651


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 22 guests