Create button to turn sound off from different layouts

0 favourites
  • 14 posts
From the Asset Store
Grenade Sound Library contains: 135 sounds 50 grenade sounds and 85 surface sounds
  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Add some logic to your events that play sounds to only play if a variable (soundEnabled) is set to True.

  • 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.

  • 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.

  • 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

  • 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.

  • 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

  • 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

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

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

    [attachment=1:1px1ezy6][/attachment:1px1ezy6]

    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:

    [attachment=0:1px1ezy6][/attachment:1px1ezy6]

    Hope this helps everybody having the same problem

  • SteveKane i fixed yours too ^^

  • Mate, thank you for that. You're an absolute legend

  • I fixed my problem with no sound on chrome !

    [attachment=0:phm7709n]

  • How do i go about saving these settings so that if someone exits the game and goes back in, these settings stay? I understand that it's with Webstorage but i've tried doing it but its not working for me. As i'm using Global Variables, i'm using that in my Webstorage expressions but its not saving the settings.

    Can someone show me or explain how it's done?

  • Anyone? I've used webstorage before but i cant get it to work with this.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)