axmol/Cocos2dSimpleGame/Cocos2dSimpleGameAppDelegat...

74 lines
2.1 KiB
C++

// Application application cpp file.
// Original file name: cocosTemplateApp.cpp
// Generated by TOPS Builder:Project wizard,Date:2010-09-27
#include "Cocos2dSimpleGameAppDelegate.h"
#include "HelloWorldScene.h"
#include "Resource.h"
using namespace cocos2d;
extern const AppResourceEntry Cocos2dSimpleGameResourceEntry;
// the works are the same as NSObject<UIApplicationDelegate>::applicationDidFinishLaunching of cocos2d-iphone
bool AppDelegate::applicationDidFinishLaunching()
{
// init the window
if (! (m_pMainWnd = new CCXEGLView(this)) || ! m_pMainWnd->Create(&m_rcWnd))
{
return false;
}
// init director
CCDirector *pDirector = CCDirector::sharedDirector();
pDirector->setOpenGLView(m_pMainWnd);
// sets landscape mode
pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
// turn on display FPS
pDirector->setDisplayFPS(true);
// set the ResourceEntry and Images ResInfo (name and ResID)
CCFileUtils::setResourceEntry(&Cocos2dSimpleGameResourceEntry);
CCFileUtils::setResourceInfo(ResInfo, sizeof(ResInfo) / sizeof(T_ResourceInfo));
// set the ResourceEntry and sound ResInfo (filename and ResID)
SimpleAudioEngine::sharedEngine()->setResourceEntry(&Cocos2dSimpleGameResourceEntry);
SimpleAudioEngine::sharedEngine()->setSoundResInfo(SoundResInfo, sizeof(SoundResInfo) / sizeof(T_SoundResInfo));
// create a scene. it's an autorelease object
CCScene *pScene = HelloWorld::scene();
// run
CCDirector::sharedDirector()->runWithScene(pScene);
return true;
}
AppDelegate::AppDelegate()
:m_rcWnd(0, 0, GetScreenWidth(), GetScreenHeight())
,m_pMainWnd(NULL)
{
}
AppDelegate::~AppDelegate()
{
SimpleAudioEngine::release();
}
void AppDelegate::applicationDidEnterBackground()
{
CCDirector::sharedDirector()->stopAnimation();
SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
}
void AppDelegate::applicationWillEnterForeground()
{
CCDirector::sharedDirector()->startAnimation();
SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
}