Page 1 of 2
Play sound
Posted: 13 March 2017, 04:19
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
Re: Play sound
Posted: 14 March 2017, 13:34
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.
Re: Play sound
Posted: 18 March 2017, 17:29
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();
Re: Play sound
Posted: 18 March 2017, 18:18
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?
Re: Play sound
Posted: 18 March 2017, 20:26
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
Re: Play sound
Posted: 18 March 2017, 20:39
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)
Re: Play sound
Posted: 30 March 2017, 12:28
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.
Re: Play sound
Posted: 30 March 2017, 14:08
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.
Re: Play sound
Posted: 30 March 2017, 14:41
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 227 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
Re: Play sound
Posted: 30 March 2017, 20:33
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).