Cocos2d 혹은 Cocos2d-X 를 이용해 게임을 개발하다가
pause/resuem 시에 앱이 제대로 동작을 하지 않거나,
뻗어버리는 현상이 발생하는 경우 경험하신 적이 있습니다.
브레이크 포인트를 걸으면 아래와 같은 Assembly String을 주며 에러를 뱉습니다.
1 |
libGPUSupportMercury.dylib`gpus_ReturnNotPermittedKillClient: |
해결책은 간단합니다.
AppDelegate 부분을 아래와 같이 코드를 수정해 주시면 됩니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
– (void)applicationDidEnterBackground:(UIApplication *)application { [[CCDirector sharedDirector] stopAnimation]; } – (void)applicationWillEnterForeground:(UIApplication *)application { [[CCDirector sharedDirector] startAnimation]; } – (void)applicationWillResignActive:(UIApplication *)application { [[CCDirector sharedDirector] pause]; } – (void)applicationDidBecomeActive:(UIApplication *)application { [[CCDirector sharedDirector] resume]; } |
Cocos2d-x의 경우엔 Appdelegate.cpp 파일에 Delegate 메세지를 받는 부분을
아래와 같이 수정합니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
// 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(); //added CCDirector::sharedDirector()->pause(); // if you use SimpleAudioEngine, it must be pause SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic(); } // this function will be called when the app is active again void AppDelegate::applicationWillEnterForeground() { CCDirector::sharedDirector()->stopAnimation(); //added CCDirector::sharedDirector()->resume(); CCDirector::sharedDirector()->startAnimation(); //added // if you use SimpleAudioEngine, it must resume here SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic(); } |
이렇게 하면 Pause/Resume 시에도 잘 돌아갑니다.
Happy Programming~!!! ^^;
답글 남기기