Open synergie7 opened 11 years ago
add audio file path to resource list,it will be preloaded automatically.
we dont need to call the function init
preload
manually
var g_ressources = [
{type:"sound", src:"res/crash.ogg"}
]
In ur code's init function
this.audioEngine = cc.AudioEngine.getInstance();
then when a "Crash" occurs,call this function
this.audioEngine.playEffect("res/crash.ogg",false);
My sound was already in the resources file.
I have removed the preload and init calls, and I was already calling playEffect
There is still a delay.
The game is on my website at
http://www.rogerclark.net/wp-content/uploads/2012/12/trafficcontrol/
When there is a crash a sprite is added where the 2 cars have crashed, and this appears immediately, but the sound doesn't seem to play immediately.
Sources are here
http://www.rogerclark.net/wp-content/uploads/2012/12/trafficcontrol/all_sources.zip
(Note the sources include cocos2d , box 2d etc etc)
Edit. I tried directly calling new Audio etc to preload the sound into a variable, but this didnt seem to help.
I think this may not be an issue with Cocos2D-HTML5 but perhaps JavaScript playback is always delayed ???
FYI.
Source code to my game has been updated and is not on github https://github.com/synergie7/cocos2d-HTML5-traffic-control
This problem seems to continue.
If you test your game offline the problem does not happen, but if you test online the problem happens the first time the sound plays, it seems that the preload of resources did not work properly and the sound did preload the first time it was played, because after that the sound works properly. But unfortunately this is a problem in a game like mine that has many sounds, it seems that it is a slow game.
Please, I'd really like to solve this, I have a very important game and that this problem condemning my game. : (
I'm using the last version of cocos2d-html5: Cocos2d-html5-v2.1.2-beta
Thanks in advance!
@zabumba69 What browser do you use to debug? some browsers don't support 'canplaythrough' event. so in fact the preload of resources did not work in this case.
I'm using Chrome and IE9.
Thanks for your fast replay, I appreciate your attention.
I'm facing same problem on Opera and IE9. I have preloaded sounds. Still the problem persists.
AudioEngine.playEffect does not play immediately even if the AudioEngine has been init'ed and the audio file has been preloaded
e.g. In my code's init function I do this
then when a "Crash" occurs, I call
this.audioEngine.playEffect("res/crash.ogg",false);
However the sound effect seems to take 1/2 sec or more to start playing.