开发者

Why is there a delay when I play a sound in Cocos2d?

I am sure there is a way to do this, and I don't know how, and am new to sound in Cocos2d. I am using SimpleAudioEngine.h as directed to in Ray Wenderlich's wonderful tutorial (P开发者_开发知识库art 1). The problem is, there is a delay when it plays a sound. I KNOW for a fact that there is a way to get rid of the delay, because, just look at all the games that are already out for iPhone!! Note that I am doing this on the Simulator, not on a real device, if that makes a difference. Any help is appreciated. Thanks!!


Have you tried preloadEffect? preload audio effects at initialize before calling playEffect:.

[[SimpleAudioEngine sharedEngine] preloadEffect:@"pew-pew-lei.caf"];


This fix might not work. If the sound engine is not initialized properly, it will never preload properly.

Another possibility of sound stuttering: your code might be asking for multiple resource files at the same time, and if you are not multi-threading, it can affect the sound effects.

To test for this: comment out your code when the sound effects play. If the sound effects do not stutter with your code commented out, that means your code is 'keeping the device or thread busy'.

I found this issue when I played an explosion animation. When I commented out the animation code, the sound effect did not stutter the game play.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜