From d2d9375376694d85cf17c7dc14fa8bf80f5c063b Mon Sep 17 00:00:00 2001 From: Walzer Date: Fri, 29 Oct 2010 06:48:00 +0000 Subject: [PATCH] add ccdirector::pause for helloworld --- HelloWorld/HelloWorld.cpp | 18 +++++++++++++++--- HelloWorld/HelloWorld.h | 2 ++ template/AppDelegate.cpp | 9 +++++++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/HelloWorld/HelloWorld.cpp b/HelloWorld/HelloWorld.cpp index 63c272543a..d7a4603198 100644 --- a/HelloWorld/HelloWorld.cpp +++ b/HelloWorld/HelloWorld.cpp @@ -49,7 +49,7 @@ bool HelloWorldAppDelegate::initCocos2d() CCDirector::getSharedDirector()->setOpenGLView(m_pMainWnd); // set to landscape mode CCDirector::getSharedDirector()->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft); - + // load background image texture and get window size CCTexture2D * pTexture = CCTextureCache::sharedTextureCache()->addImage(IMG_PATH); CGSize size = CCDirector::getSharedDirector()->getWinSize(); @@ -57,8 +57,8 @@ bool HelloWorldAppDelegate::initCocos2d() // create sprite instance CCSprite * pSprite = CCSprite::spriteWithTexture(pTexture); pSprite->setPosition(CGPoint(size.width / 2, size.height / 2)); - - // create layer instance + + // create layer instance CCLayer * pLayer = MyLayer::node(); pLayer->addChild(pSprite); @@ -92,6 +92,18 @@ Boolean HelloWorldAppDelegate::EventHandler(EventType* pEvent) return (bHandled) ? TRUE : CCXApplication::EventHandler(pEvent); } +// This function will be called when the app is inactive. When comes a phone call,it's be invoked too +void HelloWorldAppDelegate::applicationDidEnterBackground() +{ + CCDirector::getSharedDirector()->stopAnimation(); +} + +// this function will be called when the app is active again +void HelloWorldAppDelegate::applicationWillEnterForeground() +{ + CCDirector::getSharedDirector()->startAnimation(); +} + // application main entry Int32 TG3AppMain(const TUChar * pAppID, UInt32 nCmd, void * pCmdParam) { diff --git a/HelloWorld/HelloWorld.h b/HelloWorld/HelloWorld.h index 283c2a5e63..d1413875fd 100644 --- a/HelloWorld/HelloWorld.h +++ b/HelloWorld/HelloWorld.h @@ -16,6 +16,8 @@ public: virtual bool initCocos2d(); virtual Boolean EventHandler(EventType * pEvent); + virtual void applicationDidEnterBackground(); + virtual void applicationWillEnterForeground(); protected: TRectangle m_rcWnd; diff --git a/template/AppDelegate.cpp b/template/AppDelegate.cpp index acbfd70ef3..daccdc3b54 100644 --- a/template/AppDelegate.cpp +++ b/template/AppDelegate.cpp @@ -89,14 +89,19 @@ Boolean AppDelegate::EventHandler(EventType* pEvent) return (bHandled) ? TRUE : CCXApplication::EventHandler(pEvent); } -// This function be called when the app unactived,(if coming a call,it's be called too) +// This function will be called when the app is inactive. When comes a phone call,it's be invoked too void AppDelegate::applicationDidEnterBackground() { CCDirector::getSharedDirector()->stopAnimation(); + + // if you use SimpleAudioEngine, it must be pause + // SimpleAudioEngine::getSharedEngine()->pauseBackgroundMusic(); } -// This function be called when the app actived again +// this function will be called when the app is active again void AppDelegate::applicationWillEnterForeground() { CCDirector::getSharedDirector()->startAnimation(); + + // SimpleAudioEngine::getSharedEngine()->resumeBackgroundMusic(); }