Best way to deal with Sound On/Off toggle?

Get help using Construct 2

Post » Thu Mar 29, 2012 2:34 am

Hi there!

It is the first time I'm messing around with sound, and I'm having a hard time trying to decide how to proceed with the ON/OFF sound toggle in the options menu.

You guys have any ideas? What's the best way to proceed with this?
(my main concerns are ease of use for the developer X game performance)

1- Using a sub-event to test a global variable (isSoundOn) whenever I have to play a sound in the game. The problem with this one is having to add a sub event everytime I want to play a sound.

2- Use a global variable to keep the sound volume (volumeLevel) that I can set to zero when the player clicks on the sound toggle. This is way more easy. My question here is: Will the sound be played even if there's no volume? Is it intensive enough for me to worry about it?

I know it's not a big deal but I'm trying to understand how audio works in HTML5

Thanks in advance!
B
107
S
40
G
10
Posts: 456
Reputation: 13,202

Post » Thu Mar 29, 2012 4:31 am

What I'd do is get the Function plugin and use function calls to play the sounds. So you have the function events in a separate group that you can disable when the toggle is set to off. That way the code that plays the sounds isn't executed and the sound doesn't play.

This has the added benefit that you aren't messing with the volume to disable sounds. So if a player sets sound volume to say 70%, if he toggles it off and on the volume will still be 70%. Also when you lower the volume the sounds still play (obviously). I've found sound to be a bit wonky still on html5 (at least for me) and even with the volume set to 0 on repeated calls the volume will spike sometimes.inkBot2012-03-29 04:37:03
B
73
S
20
G
10
Posts: 524
Reputation: 9,896

Post » Thu Mar 29, 2012 8:37 am

@inkBot
If I could give you extra Rep I'd be doing it right now!

Of course! I'm so stupid!
I'm always talking about how the function plugin is great, and I totally forgot I could use it to make this.

I'm gonna try that, and see how it goes.
Thanks!
B
107
S
40
G
10
Posts: 456
Reputation: 13,202

Post » Wed Jul 25, 2012 11:14 am

LOL I was searching in the forums about sound volume, and found my own topic!
Anyway, method number 1 works GREAT!
B
107
S
40
G
10
Posts: 456
Reputation: 13,202

Post » Tue Jan 08, 2013 4:15 am

Using the Audio Object you can Set Silent Mode to Silent | Not Silent | or Toggle Silent

So if you just Toggle Silent on a Key Press of S it will alternately go silent and not silent
B
13
S
4
G
3
Posts: 75
Reputation: 3,425


Return to How do I....?

Who is online

Users browsing this forum: gregorysforster and 17 guests