axmol/template/AppDelegate.cpp

76 lines
1.9 KiB
C++
Raw Normal View History

// Application application cpp file.
// Original file name: cocosTemplateApp.cpp
// Generated by TOPS Builder:Project wizard,Date:2010-09-27
#include "cocos2d.h"
#include "AppDelegate.h"
#include "HelloWorldScene.h"
2010-10-11 15:28:58 +08:00
#include "Resource.h"
using namespace cocos2d;
2010-10-11 15:28:58 +08:00
extern const AppResourceEntry cocosTemplateResourceEntry;
2010-11-11 11:18:58 +08:00
bool AppDelegate::applicationDidFinishLaunching()
{
2010-11-11 11:18:58 +08:00
// init the window
if (!(m_pMainWnd = new CCXEGLView(this)) ||
! m_pMainWnd->Create(&TRectangle(0,0,GetScreenWidth(),GetScreenHeight())))
2010-11-11 11:18:58 +08:00
{
delete m_pMainWnd;
return false;
}
// init director
2010-11-11 11:18:58 +08:00
CCDirector *pDirector = CCDirector::sharedDirector();
pDirector->setOpenGLView(m_pMainWnd);
// sets landscape mode
pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
// turn on display FPS
pDirector->setDisplayFPS(true);
2010-10-11 15:28:58 +08:00
// set the ResourceEntry
CCFileUtils::setResourceEntry(&cocosTemplateResourceEntry);
2010-10-11 15:28:58 +08:00
2010-10-12 11:52:11 +08:00
// set the Images ResInfo (name and ResID)
CCFileUtils::setResourceInfo(ResInfo, sizeof(ResInfo) / sizeof(T_ResourceInfo));
2010-10-11 15:28:58 +08:00
// create a scene. it's an autorelease object
CCScene *pScene = HelloWorld::scene();
// run
2010-11-11 11:18:58 +08:00
CCDirector::sharedDirector()->runWithScene(pScene);
return true;
}
AppDelegate::AppDelegate()
:m_pMainWnd(NULL)
{
}
2010-10-29 14:48:00 +08:00
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
void AppDelegate::applicationDidEnterBackground()
{
2010-11-11 11:18:58 +08:00
CCDirector::sharedDirector()->stopAnimation();
2010-10-29 14:48:00 +08:00
// if you use SimpleAudioEngine, it must be pause
2010-11-16 15:12:09 +08:00
// SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
}
2010-10-29 14:48:00 +08:00
// this function will be called when the app is active again
void AppDelegate::applicationWillEnterForeground()
{
2010-11-11 11:18:58 +08:00
CCDirector::sharedDirector()->startAnimation();
2010-10-29 14:48:00 +08:00
2010-11-11 11:18:58 +08:00
// if you use SimpleAudioEngine, it must resume here
2010-11-16 15:12:09 +08:00
// SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
}