2010-11-27 18:25:31 +08:00
|
|
|
// 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"
|
|
|
|
|
|
|
|
using namespace cocos2d;
|
|
|
|
|
|
|
|
|
|
|
|
AppDelegate::AppDelegate()
|
|
|
|
:m_pMainWnd(NULL)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
AppDelegate::~AppDelegate()
|
|
|
|
{
|
|
|
|
#if defined(CCX_PLATFORM_WIN32)
|
|
|
|
CCX_SAFE_DELETE(m_pMainWnd);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AppDelegate::applicationDidFinishLaunching()
|
|
|
|
{
|
|
|
|
// init the window
|
|
|
|
#if defined(CCX_PLATFORM_UPHONE)
|
|
|
|
if (!(m_pMainWnd = new CCXEGLView(this)) ||
|
|
|
|
! m_pMainWnd->Create(&TRectangle(0,0,GetScreenWidth(),GetScreenHeight())))
|
|
|
|
#elif defined(CCX_PLATFORM_WIN32)
|
|
|
|
if (! (m_pMainWnd = new CCXEGLView()) ||
|
|
|
|
! m_pMainWnd->Create(L"HelloWorld", 320, 480))
|
|
|
|
#elif defined(CCX_PLATFORM_IPHONE)
|
2010-12-21 07:41:23 +08:00
|
|
|
if (! (m_pMainWnd = new CCXEGLView() ) )
|
2010-12-18 18:23:31 +08:00
|
|
|
#elif defined(CCX_PLATFORM_ANDROID)
|
|
|
|
if (!(m_pMainWnd = CCDirector::sharedDirector()->getOpenGLView()))
|
2010-11-27 18:25:31 +08:00
|
|
|
#else
|
|
|
|
#error
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
delete m_pMainWnd;
|
|
|
|
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);
|
|
|
|
|
2011-01-19 18:23:42 +08:00
|
|
|
// set FPS. the default value is 1.0/60 if you don't call this
|
2011-01-20 10:49:30 +08:00
|
|
|
pDirector->setAnimationInterval(1.0 / 60);
|
2011-01-19 18:23:42 +08:00
|
|
|
|
2010-11-27 18:25:31 +08:00
|
|
|
// create a scene. it's an autorelease object
|
|
|
|
CCScene *pScene = HelloWorld::scene();
|
|
|
|
|
|
|
|
// run
|
|
|
|
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()
|
|
|
|
{
|
2010-12-03 15:27:55 +08:00
|
|
|
CCDirector::sharedDirector()->pause();
|
2010-11-27 18:25:31 +08:00
|
|
|
|
|
|
|
// if you use SimpleAudioEngine, it must be pause
|
|
|
|
// SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
|
|
|
|
}
|
|
|
|
|
|
|
|
// this function will be called when the app is active again
|
|
|
|
void AppDelegate::applicationWillEnterForeground()
|
|
|
|
{
|
2010-12-03 15:27:55 +08:00
|
|
|
CCDirector::sharedDirector()->resume();
|
2010-11-27 18:25:31 +08:00
|
|
|
|
|
|
|
// if you use SimpleAudioEngine, it must resume here
|
|
|
|
// SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
|
|
|
|
}
|