2010-10-01 07:35:28 +08:00
|
|
|
// Application application cpp file.
|
|
|
|
|
|
|
|
// Original file name: cocosTemplateApp.cpp
|
|
|
|
// Generated by TOPS Builder:Project wizard,Date:2010-09-27
|
|
|
|
|
2010-10-01 22:52:15 +08:00
|
|
|
#include "Cocos2dSimpleGameAppDelegate.h"
|
2010-10-01 07:35:28 +08:00
|
|
|
#include "HelloWorldScene.h"
|
2010-10-12 16:14:34 +08:00
|
|
|
#include "Resource.h"
|
2010-10-01 07:35:28 +08:00
|
|
|
|
|
|
|
using namespace cocos2d;
|
2010-10-12 16:14:34 +08:00
|
|
|
extern const AppResourceEntry Cocos2dSimpleGameResourceEntry;
|
2010-10-01 07:35:28 +08:00
|
|
|
|
2010-10-01 22:52:15 +08:00
|
|
|
// the works are the same as NSObject<UIApplicationDelegate>::applicationDidFinishLaunching of cocos2d-iphone
|
2010-11-11 11:53:04 +08:00
|
|
|
bool AppDelegate::applicationDidFinishLaunching()
|
2010-10-01 22:52:15 +08:00
|
|
|
{
|
2010-11-11 11:53:04 +08:00
|
|
|
// init the window
|
|
|
|
if (! (m_pMainWnd = new CCXEGLView(this)) || ! m_pMainWnd->Create(&m_rcWnd))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2010-10-01 22:52:15 +08:00
|
|
|
// init director
|
2010-11-11 11:18:58 +08:00
|
|
|
CCDirector *pDirector = CCDirector::sharedDirector();
|
2010-10-01 22:52:15 +08:00
|
|
|
pDirector->setOpenGLView(m_pMainWnd);
|
|
|
|
|
|
|
|
// sets landscape mode
|
|
|
|
pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
|
|
|
|
|
|
|
|
// turn on display FPS
|
|
|
|
pDirector->setDisplayFPS(true);
|
|
|
|
|
2010-10-13 14:18:03 +08:00
|
|
|
// set the ResourceEntry and Images ResInfo (name and ResID)
|
2010-10-19 17:08:25 +08:00
|
|
|
CCFileUtils::setResourceEntry(&Cocos2dSimpleGameResourceEntry);
|
|
|
|
CCFileUtils::setResourceInfo(ResInfo, sizeof(ResInfo) / sizeof(T_ResourceInfo));
|
2010-10-12 16:14:34 +08:00
|
|
|
|
2010-10-13 14:18:03 +08:00
|
|
|
// set the ResourceEntry and sound ResInfo (filename and ResID)
|
2010-10-18 15:07:55 +08:00
|
|
|
SimpleAudioEngine::getSharedEngine()->setResourceEntry(&Cocos2dSimpleGameResourceEntry);
|
|
|
|
SimpleAudioEngine::getSharedEngine()->setSoundResInfo(SoundResInfo, sizeof(SoundResInfo) / sizeof(T_SoundResInfo));
|
2010-10-13 14:18:03 +08:00
|
|
|
|
2010-10-01 22:52:15 +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);
|
2010-10-01 22:52:15 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2010-10-01 07:35:28 +08:00
|
|
|
|
|
|
|
AppDelegate::AppDelegate()
|
|
|
|
:m_rcWnd(0, 0, GetScreenWidth(), GetScreenHeight())
|
|
|
|
,m_pMainWnd(NULL)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
AppDelegate::~AppDelegate()
|
|
|
|
{
|
2010-11-11 11:53:04 +08:00
|
|
|
SimpleAudioEngine::release();
|
2010-10-27 16:07:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AppDelegate::applicationDidEnterBackground()
|
|
|
|
{
|
2010-11-11 11:18:58 +08:00
|
|
|
CCDirector::sharedDirector()->stopAnimation();
|
2010-10-27 16:07:04 +08:00
|
|
|
|
|
|
|
SimpleAudioEngine::getSharedEngine()->pauseBackgroundMusic();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AppDelegate::applicationWillEnterForeground()
|
|
|
|
{
|
2010-11-11 11:18:58 +08:00
|
|
|
CCDirector::sharedDirector()->startAnimation();
|
2010-10-27 16:07:04 +08:00
|
|
|
|
|
|
|
SimpleAudioEngine::getSharedEngine()->resumeBackgroundMusic();
|
|
|
|
}
|