2010-11-16 11:25:33 +08:00
|
|
|
#include "AppDelegate.h"
|
2011-01-18 15:32:29 +08:00
|
|
|
|
2011-03-01 14:28:39 +08:00
|
|
|
#include "cocos2d.h"
|
2011-03-09 15:35:06 +08:00
|
|
|
[! if CC_USE_COCOS_DENSHION_SIMPLE_AUDIO_ENGINE]
|
2010-12-03 15:27:55 +08:00
|
|
|
#include "SimpleAudioEngine.h"
|
2010-12-25 15:44:26 +08:00
|
|
|
using namespace CocosDenshion;
|
2010-11-16 11:25:33 +08:00
|
|
|
|
2010-12-03 15:27:55 +08:00
|
|
|
[! endif]
|
2010-11-16 11:25:33 +08:00
|
|
|
#include "HelloWorldScene.h"
|
|
|
|
|
|
|
|
using namespace cocos2d;
|
|
|
|
|
|
|
|
AppDelegate::AppDelegate()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
AppDelegate::~AppDelegate()
|
|
|
|
{
|
2011-03-09 15:35:06 +08:00
|
|
|
[! if CC_USE_COCOS_DENSHION_SIMPLE_AUDIO_ENGINE]
|
2011-01-18 15:32:29 +08:00
|
|
|
SimpleAudioEngine::end();
|
2010-11-26 15:36:44 +08:00
|
|
|
[! endif]
|
2010-11-16 11:25:33 +08:00
|
|
|
}
|
|
|
|
|
2011-03-01 14:28:39 +08:00
|
|
|
bool AppDelegate::initInstance()
|
2010-11-16 11:25:33 +08:00
|
|
|
{
|
2011-03-01 14:28:39 +08:00
|
|
|
bool bRet = false;
|
|
|
|
do
|
2011-01-18 15:32:29 +08:00
|
|
|
{
|
2011-03-01 14:28:39 +08:00
|
|
|
// Initialize OpenGLView instance, that release by CCDirector when application terminate.
|
|
|
|
// The HelloWorld is designed as HVGA.
|
2011-03-09 15:35:06 +08:00
|
|
|
// Use GetScreenWidth() and GetScreenHeight() get screen width and height.
|
|
|
|
CCEGLView * pMainWnd = new CCEGLView(this);
|
|
|
|
CC_BREAK_IF(! pMainWnd
|
|
|
|
|| ! pMainWnd->Create(&TRectangle(0, 0, 320, 480)));
|
2011-03-01 14:28:39 +08:00
|
|
|
|
|
|
|
bRet = true;
|
|
|
|
} while (0);
|
|
|
|
return bRet;
|
|
|
|
}
|
2010-11-16 11:25:33 +08:00
|
|
|
|
2011-03-01 14:28:39 +08:00
|
|
|
bool AppDelegate::applicationDidFinishLaunching()
|
|
|
|
{
|
|
|
|
// initialize director
|
|
|
|
CCDirector *pDirector = CCDirector::sharedDirector();
|
2011-03-09 15:35:06 +08:00
|
|
|
pDirector->setOpenGLView(&CCEGLView::sharedOpenGLView());
|
2011-03-01 14:28:39 +08:00
|
|
|
|
|
|
|
// sets landscape mode
|
2010-11-16 11:25:33 +08:00
|
|
|
pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
|
2011-03-01 14:28:39 +08:00
|
|
|
|
|
|
|
// turn on display FPS
|
2010-11-16 11:25:33 +08:00
|
|
|
pDirector->setDisplayFPS(true);
|
|
|
|
|
2011-03-01 14:28:39 +08:00
|
|
|
// set FPS. the default value is 1.0/60 if you don't call this
|
|
|
|
pDirector->setAnimationInterval(1.0 / 60);
|
2010-11-16 11:25:33 +08:00
|
|
|
|
2011-03-01 14:28:39 +08:00
|
|
|
// create a scene. it's an autorelease object
|
|
|
|
CCScene *pScene = HelloWorld::scene();
|
2010-11-16 11:25:33 +08:00
|
|
|
|
2011-03-01 14:28:39 +08:00
|
|
|
// run
|
2011-01-18 15:32:29 +08:00
|
|
|
pDirector->runWithScene(pScene);
|
2010-11-16 11:25:33 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-01-18 15:32:29 +08:00
|
|
|
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
2010-11-16 11:25:33 +08:00
|
|
|
void AppDelegate::applicationDidEnterBackground()
|
|
|
|
{
|
2010-12-03 15:27:55 +08:00
|
|
|
CCDirector::sharedDirector()->pause();
|
2011-03-09 15:35:06 +08:00
|
|
|
[! if CC_USE_COCOS_DENSHION_SIMPLE_AUDIO_ENGINE]
|
2010-12-03 15:27:55 +08:00
|
|
|
|
|
|
|
SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
|
|
|
|
[! endif]
|
2010-11-16 11:25:33 +08:00
|
|
|
}
|
|
|
|
|
2011-01-18 15:32:29 +08:00
|
|
|
// this function will be called when the app is active again
|
2010-11-16 11:25:33 +08:00
|
|
|
void AppDelegate::applicationWillEnterForeground()
|
|
|
|
{
|
2010-12-03 15:27:55 +08:00
|
|
|
CCDirector::sharedDirector()->resume();
|
2011-03-09 15:35:06 +08:00
|
|
|
[! if CC_USE_COCOS_DENSHION_SIMPLE_AUDIO_ENGINE]
|
2010-12-03 15:27:55 +08:00
|
|
|
|
|
|
|
SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
|
|
|
|
[! endif]
|
2010-11-16 11:25:33 +08:00
|
|
|
}
|