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
108
S
40
G
10
Posts: 456
Reputation: 13,252

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
108
S
40
G
10
Posts: 456
Reputation: 13,252

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
108
S
40
G
10
Posts: 456
Reputation: 13,252

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

Post » Mon Apr 17, 2017 9:12 am

This is a bit of an older post, but it is still the first post that comes up in a search.
I didn't want to make a new topic, that being said I have two sound related questions.

Does 'Silent Mode' still load sounds into memory?

I have a question about preloading a sound, can somebody explain what it does?

The Manual and Description in C2 says it downloads an audio file online from a server.
The 'Preload' description uses the term preload a lot.

By Definition preloading means loading a file into memory before using it, and download means getting a file from another computer or server.
You have to download a file from another computer before you can preload it into memory.

An action exists called "Unload Audio".
The description given say it "removes audio from memory", this implies 'Preload' loads audio to memory.

So can someone clear up what Preloading a sound file does?
Is it for downloading audio files from a server and/or preloading local sounds into memory so it plays better?

I have been preloading local sounds before they are needed. I don't know if I need to be doing this or not.
B
50
S
30
G
12
Posts: 203
Reputation: 11,006

Post » Mon Apr 17, 2017 11:52 am

on start of the layout
if "sound" is not playing > then play "sound"
Image
B
57
S
34
G
28
Posts: 528
Reputation: 22,068

Post » Mon Apr 17, 2017 12:59 pm

Preloading will download sounds into memory so that they play as soon as they're called - if they're not preloaded then when they're called there might be a delay before they play as it will take a little bit of time to download them.

By default, sounds are automatically preloaded when the game is initially downloaded by the user but you can turn this feature off in the project settings - you may want to do this if you have lots of sounds and would like to reduce the initial loading time - you could then preload groups of sounds on a level-by-level basis, for example.

Sounds take up space in memory, so if you have lots of sounds in memory that aren't going to be reused and your game is particularly memory hungry then you may want to clear up some space by unloading them. I assume that unloaded sounds would then need to be re-downloaded if they are called again.

Hope that helps :)
B
9
S
3
Posts: 83
Reputation: 1,097

Post » Mon Apr 17, 2017 10:38 pm

I understand what the action of preloading something does and the use for it.

The descriptions for 'Preload' in C2 threw me off a small bit.
I just don't understand why the term 'download' and the phrase 'downloads from server' is being used to describe 'preload'.

Preloading and downloading are two different things.
By using the word 'download' it implies getting the file from a network or a different computer.

I didn't think loading a file into memory is considered downloading. I am just confused on why the term download is being used.
The sounds are downloaded when the game is downloaded.
Sounds are loaded or preloaded when the game is running.

It just seems like I am missing something.
Can you download a sound file from a link as well as loading from local?
B
50
S
30
G
12
Posts: 203
Reputation: 11,006


Return to How do I....?

Who is online

Users browsing this forum: newt, skrotar, yme, Youtopize and 11 guests