How do I stop playing sound effect after button is tapped

Get help using Construct 2

Post » Thu Jul 07, 2016 5:50 am

I have 4 buttons on the main menu. When a button is tapped a sound plays, a black background fades in and you are taken to the corresponding layout.

The problem is, during the fade in of the black background you can click on any of the buttons and the sound can still play.

I've been looking for the longest time for a solution on how to stop the sound from playing when any button is tapped. I've tried things like:

Add an Audio is tag playing condition to the button clicked event and invert it..

...make a global variable that tracks if the button was clicked, where on its first click, it'll set it to 1 and allow a song to play, but if you click again, it is set to 2 and won't play.

"On button clicked -> Sys: Add 1 to variable -> | if variable = 1 -> play sound"

Take your button sprite and create boolean variable. Name it something like "Is_Playing". Now events:
Main Event
On BUTTON clicked
Sub-Events
- Is_Playing : Stop, toggle boolean "Is_Playing"
- Else : Play, toggle boolean "Is_Playing"


I guess i'm just not C2 savy enough to understand why any of these just won't work.

Image
[/img]


If anyone can help explain things, i'd be very grateful.
B
38
S
18
G
19
Posts: 664
Reputation: 14,112

Post » Thu Jul 07, 2016 5:54 am

You can put your On touched events in a Group (like Menu Buttons) and Deactivate the group when any button is pressed. This will block any more button events until you Activate the group again.
ImageImageImage
B
71
S
22
G
248
Posts: 3,761
Reputation: 138,073

Post » Thu Jul 07, 2016 6:26 am

Oh you are so awesome!

That was too easy. Learn something new everyday.



Thank you again.
B
38
S
18
G
19
Posts: 664
Reputation: 14,112


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 26 guests