Play sound

Game development with Board Game Arena Studio
User avatar
Morgalad
Posts: 110
Joined: 17 January 2017, 20:46
Contact:

Play sound

Post by Morgalad »

Now that I have the dice almost ready I'm wondering how to play roll dice sound. I've tried with the functions included on the studio but these seem to be limited to the ones on the Theme list.

Do you have some advice of how to play a dice rolling sound?

I already found from a copyleft repository a nice dice rolling sound
Last edited by Morgalad on 30 March 2017, 15:10, edited 1 time in total.
Cheers...
Morgalad

Developer of: Incan Gold , Takara Island , Taluva and Veggie Garden
User avatar
Victoria_La
Posts: 665
Joined: 28 December 2015, 20:55

Re: Play sound

Post by Victoria_La »

I tried to hack it up myself to play choo-choo sound for my train game, but it seems overly complicated.
The no documented API in studio for that. The code that deals with this has a lot of ifs and using different frameworks in different conditions,
it also uses sounds catalogue which is hard-coded in framework. Unless they already have this sound it would be very hard
to implement it and not worth it imho. There are few games that use dice (such as can't stop) but I don't know if they use sounds for that.
Or wait till April when Een comes back and may answer this question.
User avatar
Morgalad
Posts: 110
Joined: 17 January 2017, 20:46
Contact:

Re: Play sound

Post by Morgalad »

Victoria_La wrote:I tried to hack it up myself to play choo-choo sound for my train game, but it seems overly complicated.
The no documented API in studio for that. The code that deals with this has a lot of ifs and using different frameworks in different conditions,
it also uses sounds catalogue which is hard-coded in framework. Unless they already have this sound it would be very hard
to implement it and not worth it imho. There are few games that use dice (such as can't stop) but I don't know if they use sounds for that.
Or wait till April when Een comes back and may answer this question.

The solutionr was much simpler than I expected...

Code: Select all

var audio = new Audio(g_gamethemeurl+'sound/diceroll.mp3');
            audio.play();
Cheers...
Morgalad

Developer of: Incan Gold , Takara Island , Taluva and Veggie Garden
User avatar
Victoria_La
Posts: 665
Joined: 28 December 2015, 20:55

Re: Play sound

Post by Victoria_La »

Cool. How did you figure it out? Is Audio part of bga API or dojo or some other library?
g_gamethemeurl is global var?
User avatar
Morgalad
Posts: 110
Joined: 17 January 2017, 20:46
Contact:

Re: Play sound

Post by Morgalad »

Victoria_La wrote:Cool. How did you figure it out? Is Audio part of bga API or dojo or some other library?
g_gamethemeurl is global var?
Audio is a DOM object supported on all modern browsers

https://www.w3schools.com/jsref/dom_obj_audio.asp

g_gamethemeurl is a default global variable created by the BGA API, it is the same used on the stock component...

so I created a sound folder and uploaded my mp3 there and that's all
Cheers...
Morgalad

Developer of: Incan Gold , Takara Island , Taluva and Veggie Garden
User avatar
Victoria_La
Posts: 665
Joined: 28 December 2015, 20:55

Re: Play sound

Post by Victoria_La »

Yeah it works, the only thing I cannot figure out is how to hook it to sound control (mute button in the game)
User avatar
Morgalad
Posts: 110
Joined: 17 January 2017, 20:46
Contact:

Re: Play sound

Post by Morgalad »

Victoria_La wrote:Yeah it works, the only thing I cannot figure out is how to hook it to sound control (mute button in the game)
Now that Een is back maybe we could have some advice from the admins on this: I plan to use this approach in my project but I would like to have some advice on how to hook this with the main sound control button.
Cheers...
Morgalad

Developer of: Incan Gold , Takara Island , Taluva and Veggie Garden
User avatar
Een
Posts: 3861
Joined: 16 June 2010, 19:52

Re: Play sound

Post by Een »

Morgalad wrote:
Victoria_La wrote:Yeah it works, the only thing I cannot figure out is how to hook it to sound control (mute button in the game)
Now that Een is back maybe we could have some advice from the admins on this: I plan to use this approach in my project but I would like to have some advice on how to hook this with the main sound control button.
Hi there! :)

You can check if sound is on or off by testing boolean "soundManager.bMuteSound".
Playing a sound can be done in a game.js through "playSound( soundId )", but only for sounds included in the sound library of the framework. Actually, when you add a sound folder on the studio, it's non-standard and so it's not included in the version control tool or in the game package created for deployment... so that will work only on the studio.
If you have a nice sound file for dice rolls, I think the best would be to send us the file so we can add it to the framework sound library, as it can be useful to other projects.
User avatar
Morgalad
Posts: 110
Joined: 17 January 2017, 20:46
Contact:

Re: Play sound

Post by Morgalad »

hi,

Thank you very much for the info Een, I'm going to do a var check on that before playing the sound so I would not annoy players.

this is the definitive sound file I'm going to use:
roll.zip
(16.3 KiB) Downloaded 226 times
really small (only 22kb) and it is a modified version by me from a copyleft sound, so no issues on that sense, if you add it to the BGA themes lib let me know and I will remove it from my img/sound folder and I will use the one from the theme.

Edit:

I've wrapped my sound play with:

Code: Select all

if ( soundManager.bMuteSound == false)
	{
	var audio = new Audio(g_gamethemeurl+'img/roll.mp3');
	audio.play();
	}
so, if they have muted the game this will not bother
Cheers...
Morgalad

Developer of: Incan Gold , Takara Island , Taluva and Veggie Garden
User avatar
Een
Posts: 3861
Joined: 16 June 2010, 19:52

Re: Play sound

Post by Een »

Morgalad wrote:if you add it to the BGA themes lib let me know and I will remove it from my img/sound folder and I will use the one from the theme.
Nice sound (even if after some rolls, I'm sure some people will complain about it ^^).
Added to the lib with soundId "die-roll" (should work right away on the studio, will be available in production after the next release).
To play from your js, use "playSound( 'die-roll' );" (check for sound on/off is included in this function, no need to recheck).
Post Reply

Return to “Developers”