Hey Adam,
R u working on the Android or iOS.
I got the same problem in Android, I simply changed some of the function in Java side, try to get rid of the preload() problem in cocos2d-x, so i can play sound effects by using playSoundEffect() directly.
But I the problem on iOS side is a little more tricky, when the game enter background and resume, the background music is always there, while the sound effects could disappear if you quit at the same time u are playing the sound effects, I think that s the reason why people said the problem happened randomly depends on the the times they entering background and resume from it.
The following are the piece of code I used for the pause and resume in AppDelegate.cpp :
// This function will be called when the app is inactive. When comes a phone call,it’s be invoked too
void AppDelegate::applicationDidEnterBackground()
{
CCDirector::sharedDirector()->stopAnimation();
CCDirector::sharedDirector()->pause();
// if you use SimpleAudioEngine, it must be pause
CocosDenshion::SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
// CocosDenshion::SimpleAudioEngine::sharedEngine()->stopAllEffects();
}
// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
{
CCDirector::sharedDirector()->stopAnimation();
CCDirector::sharedDirector()->resume();
CCDirector::sharedDirector()->startAnimation();
// if you use SimpleAudioEngine, it must resume here
CocosDenshion::SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
// CocosDenshion::SimpleAudioEngine::sharedEngine()->resumeAllEffects();
}
I comment out the stopAllEffects() and resumeAllEffects() is because I tried on the them and that doesn’t actually work.
Adam Reed wrote:
I also have an issue where the preloaded sound effect will stop working.
I can cause this by loading a level, exiting the level and loading it again.
Background music is ok but not effects.
For me, I don’t have to exit the app itself, just the level.
>
I wondered if pre-loading the same effect again would be causing it?
I tried to unload the effect but was receiving an error.