Simple On/Off Button

Get help using Construct 2

Post » Thu Sep 05, 2013 8:13 pm

I have been trying for a while to create this but I can't get it working.

This is a Coccoon project so I am using touch.

I followed this post http://www.scirra.com/forum/game-sound-On-off-button-issue_topic46140.html but this uses mouse events.

I thought to create a sprite with 2 frames and alternate between frame 0 and 1, I can only get it working one way though - switches to frame 1 but can't switch back to frame 0.

Any help welcome.


image upload software
B
10
Posts: 30
Reputation: 940

Post » Thu Sep 05, 2013 8:23 pm

Events are processed one after the other, so what you have done is test for a condition, set the frame and music, but the very next event sets them back again.

There are many ways to deal with this, but the easiest is to just use 'Else'.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
132
S
29
G
81
Posts: 5,329
Reputation: 56,657

Post » Thu Sep 05, 2013 8:23 pm

you can do 1-variable as a neat way of making it toggle between 1 and 0 with one event:


+ Is in touch   
> buttonMusic1 | set animation frame to music
> system       | set music to 1-musickeepee2013-09-05 20:24:36
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Thu Sep 05, 2013 9:49 pm

[QUOTE=zenox98] Events are processed one after the other, so what you have done is test for a condition, set the frame and music, but the very next event sets them back again.

There are many ways to deal with this, but the easiest is to just use 'Else'.[/QUOTE]

Yes that's exactly what I wanted to do, set the frame and music then if the user wishes set them back again.

I can't see how your solution sets the button back - to explain I want frame 0 to show then when the button is pressed frame 1 shows, pressed again frame 0 shows etc. A simple on/off. I have tried every conceivable variant of touch and I can't get it to work.
B
10
Posts: 30
Reputation: 940

Post » Thu Sep 05, 2013 10:01 pm

You misunderstand how the events work. The way you have it setup means that the first condition, if set, will 'automatically' trigger the next condition, even without touching it.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
132
S
29
G
81
Posts: 5,329
Reputation: 56,657

Post » Thu Sep 05, 2013 10:01 pm

@keepee heh, I usually do that using var * -1, then check if it's -1 or 1. Your way looks prettier though
B
122
S
42
G
40
Posts: 846
Reputation: 27,994

Post » Thu Sep 05, 2013 10:24 pm

@andreyin
sometimes toggling 1 and -1 is useful though, so I'll remember yours too
yay learning
B
28
S
8
G
1
Posts: 469
Reputation: 4,683


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 4 guests