Create button to turn sound off from different layouts

Just started using Construct 2? Post your questions here

Post » Mon May 12, 2014 3:30 pm

I'm trying to create a button to turn sound effects off on another layout but I'm having a little trouble with it. I have three layouts, Menu, Game & Game Over. On my menu i've created two buttons, one to turn the music off and one to turn sound effects off.

My music starts on the start of the Menu layout so the music button is working perfectly and turns the music on or off with no issues.

However my sound button doesn't fully work as I want this to just turn off sound that plays on all three layouts. I have sound that plays when a button is pressed which is on the Menu & Game Over layout. I also have sound on my Game layout where it makes a sound when the play jumps. I want my sound button to turn all these sounds off when toggled but I can only seem to make it work for the sounds on the Menu layout.

The way I've done my buttons is when it is set to animation frame 0, the music/sound plays. When it is set to frame 1, it should stop/ mute.

Hope someone can help, ive had various different attempts to solve this but to no avail.

I've provided a capx file that i've been working on. So far it just the autorunner game with few added bits such as menu, sound etc.

Thanks.
You do not have the required permissions to view the files attached to this post.
B
5
S
2
Posts: 116
Reputation: 867

Post » Mon May 12, 2014 4:44 pm

Add some logic to your events that play sounds to only play if a variable (soundEnabled) is set to True.
B
49
S
12
G
10
Posts: 1,833
Reputation: 14,583

Post » Mon May 12, 2014 7:14 pm

I've tried but i can't get it to work. Would you be able to do it with the capx ive provided? I'm just having alot of trouble turning off sound over three layouts, I've had many attempts but to no avail. I know it can be done as if I set audio to silent on animation frame 1, everything is muted but I don't want the music muted with this button as my other button does that.

I would appreciate it if you can do it with the capx file so I can see where I'm going wrong.
B
5
S
2
Posts: 116
Reputation: 867

Post » Mon May 12, 2014 9:55 pm

Between my 6 hour commute and trying to sell my house, it may not be until this weekend that I would get a chance to actually crack open the capx.
B
49
S
12
G
10
Posts: 1,833
Reputation: 14,583

Post » Tue May 13, 2014 12:27 am

Hi SteveKane,

you will have to manually set the audio you don't want to play.

Create a global variable called 'mute'

if mute = 1, stop are the music manually.

Then on start of layout if mute = 1, stop selected music.

If that doesn't work, where you have the audio. (when the player die)

PlayerHealth = 0
Mute = 0
play audio 'dead'

that would prevent the audio from playing as mute is set to 1.

Hope that works :)
B
16
S
4
Posts: 69
Reputation: 1,834

Post » Tue May 13, 2014 3:02 pm

I've managed to solve my issue using a Global Variable, i found out where i was going wrong so i've fixed that so hopefully they'll be no more issues with that. Thanks BluePhaze & federer365 for your responses, appriciate you guys taking time out to help out.

I do have another issue that's slightly related, the issue is that on my game over screen, if you select the Menu button it goes to the Main Menu layout, which is fine but in doing this the Music and Sound button reset to default, so they start playing again when you press the Menu button, even if the sound has been turned off before.

I know this is because i've set it to go to the Main Menu layout after touch the button and so the Main Menu layout resets to the beginning but i can't work around how to keep the Music and Sound setting when going back to this layout.

I've provided my capx again as i noticed an error in the capx that i originally posted where the music button didn't work as i forgot to set a tag to an audio file.
You do not have the required permissions to view the files attached to this post.
B
5
S
2
Posts: 116
Reputation: 867

Post » Tue May 13, 2014 11:43 pm

Hello everybody :) I'm new to construct 2 so im not very skilled right now. One week ago i run into exactly the same problem like SteveKane. I have searched like a maniac on google and here on this side but i couldnt find something helpfull (except the basic audio tutorials).

So my problem is: I have 3 layouts (Start, Game and End) on the first layout (Start) i made 2 buttons to toggle (mute/unmute) music and sound the music starts on the first layout and the mute/unmute works perfect. The problem is mute/unmute sound, if i mute musik its muted on all three layouts the sound is just muted on the middle layout and on the other both (start and end layout) the sound still plays. I dont want to upload my whole project here so i decided to make a new project only with the music and sound i have on my main project. But now as i finished everything i realised that toggle mute/unmute sound is working on all three layouts, i have to check my main project again! After some more testing on the new sound project i noticed also when toggle mute is set it still plays sound sometimes (random). NOW THE IMPORTANT THIS HAPPENS ON FIREFOX I HAVE TRIED IT ON CHROME TOO BUT THERE IS GENERALLY NO SOUND (MUSIC WORKS FINE). Btw im on xp professional sp3.

Maybe some of you guys can help me by making a clear screenshot of some working toggle-sound-music menu or upload some construct 2 file or link me to some advanced sound tutorial that i have may not seen on the net^^ I need really help, and yes i have also read the tips above but as said before im new and some file or picture of how to do would be great. Thx in advance!!! I ADDED MY AUDIO PROJECT (Test_sound_mabk).

Regards Mabk :)
You do not have the required permissions to view the files attached to this post.
B
8
S
2
Posts: 5
Reputation: 1,311

Post » Wed May 14, 2014 2:29 pm

Ok me again, i tried the whole night now to figure out whats the difference between my main project and the test_sound project i made, but there isnt any its 1:1 the same no wrong tag or variable nothing (+ after i couldnt find something i deleted the whole sound and wrote everything new 1:1, again sound mutes only on the middle layout). And the random sound plays on the middle layout on set mute too what i didnt notice before because its not as often. My main browser is firefox but i tried it on chrome to a second time and now i have generally sound but with the same random sound noices and layout problem - but i didnt made any chance - i have only restarted my pc a couple of times since my last post !?!?!?!

Regards Mabk
B
8
S
2
Posts: 5
Reputation: 1,311

Post » Wed May 14, 2014 9:25 pm

I FIXED IT - the problem was the mute/unmute function on sound.

I figured out how to use an "if function" as stated above :D

if_condition_sound.jpg


Now the sound is really muted on all layout and no random play.

The only is i dont know why on chrome sometimes i dont have sound .... music is working and the file format is correct too!

I have added the fixed construct file.

Edit: On my main project i have addet it now as sub event not as condition!

Like this:
subevent_toggle_sound.jpg


Hope this helps everybody having the same problem :)
You do not have the required permissions to view the files attached to this post.
Last edited by Anonymous29 on Thu May 15, 2014 1:53 am, edited 1 time in total.
B
8
S
2
Posts: 5
Reputation: 1,311

Post » Thu May 15, 2014 12:14 am

@SteveKane i fixed yours too ;) ^^
You do not have the required permissions to view the files attached to this post.
B
8
S
2
Posts: 5
Reputation: 1,311

Next

Return to Beginner's Questions

Who is online

Users browsing this forum: Obi554 and 2 guests