axmol/template/CCXAppWiz.vs/CCXAppWiz.uphone/Templates/1033/Classes/AppDelegate.cpp

69 lines
1.7 KiB
C++

#include "AppDelegate.h"
[! if CCX_USE_COCOS_DENSHION_SIMPLE_AUDIO_ENGINE]
#include "SimpleAudioEngine.h"
using namespace CocosDenshion;
[! endif]
#include "HelloWorldScene.h"
using namespace cocos2d;
AppDelegate::AppDelegate()
:m_pMainWnd(NULL)
{
}
AppDelegate::~AppDelegate()
{
[! if CCX_USE_COCOS_DENSHION_SIMPLE_AUDIO_ENGINE]
SimpleAudioEngine::end();
[! endif]
}
bool AppDelegate::applicationDidFinishLaunching()
{
// init the window
if (!(m_pMainWnd = new CCXEGLView(this)) ||
! m_pMainWnd->Create(&TRectangle(0,0,GetScreenWidth(),GetScreenHeight())))
{
CCX_SAFE_DELETE(m_pMainWnd);
return false;
}
// init director
CCDirector * pDirector = CCDirector::sharedDirector();
pDirector->setOpenGLView(m_pMainWnd);
pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
// pDirector->setDeviceOrientation(kCCDeviceOrientationPortrait);
pDirector->setDisplayFPS(true);
CCScene * pScene = HelloWorld::scene();
pDirector->runWithScene(pScene);
return true;
}
// 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()->pause();
[! if CCX_USE_COCOS_DENSHION_SIMPLE_AUDIO_ENGINE]
SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
[! endif]
}
// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
{
CCDirector::sharedDirector()->resume();
[! if CCX_USE_COCOS_DENSHION_SIMPLE_AUDIO_ENGINE]
SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
[! endif]
}