2010-11-16 11:25:33 +08:00
|
|
|
#include "AppDelegate.h"
|
2011-01-18 15:32:29 +08:00
|
|
|
|
2011-03-01 14:28:39 +08:00
|
|
|
#include "cocos2d.h"
|
2011-03-09 15:35:06 +08:00
|
|
|
[! if CC_USE_COCOS_DENSHION_SIMPLE_AUDIO_ENGINE]
|
2010-12-03 15:27:55 +08:00
|
|
|
#include "SimpleAudioEngine.h"
|
2010-12-25 15:44:26 +08:00
|
|
|
using namespace CocosDenshion;
|
2010-11-16 11:25:33 +08:00
|
|
|
|
2010-12-03 15:27:55 +08:00
|
|
|
[! endif]
|
2010-11-16 11:25:33 +08:00
|
|
|
#include "HelloWorldScene.h"
|
|
|
|
|
|
|
|
using namespace cocos2d;
|
|
|
|
|
|
|
|
AppDelegate::AppDelegate()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
AppDelegate::~AppDelegate()
|
|
|
|
{
|
2011-03-09 15:35:06 +08:00
|
|
|
[! if CC_USE_COCOS_DENSHION_SIMPLE_AUDIO_ENGINE]
|
2011-01-18 15:32:29 +08:00
|
|
|
SimpleAudioEngine::end();
|
2010-11-26 15:36:44 +08:00
|
|
|
[! endif]
|
2010-11-16 11:25:33 +08:00
|
|
|
}
|
|
|
|
|
2011-03-01 14:28:39 +08:00
|
|
|
bool AppDelegate::initInstance()
|
2010-11-16 11:25:33 +08:00
|
|
|
{
|
2011-03-01 14:28:39 +08:00
|
|
|
bool bRet = false;
|
|
|
|
do
|
2011-01-18 15:32:29 +08:00
|
|
|
{
|
2011-03-17 11:27:51 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
|
|
|
// Initialize OpenGLView instance, that release by CCDirector when application terminate.
|
|
|
|
// The HelloWorld is designed as HVGA.
|
|
|
|
CCEGLView * pMainWnd = new CCEGLView();
|
|
|
|
CC_BREAK_IF(! pMainWnd
|
|
|
|
|| ! pMainWnd->Create(TEXT("[!output PROJECT_NAME]"), 320, 480));
|
|
|
|
#endif // CC_PLATFORM_WIN32
|
|
|
|
|
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
|
|
|
|
|
|
|
// OpenGLView initialized in testsAppDelegate.mm on ios platform, nothing need to do here.
|
|
|
|
|
|
|
|
#endif // CC_PLATFORM_IOS
|
|
|
|
|
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
|
|
|
|
|
|
|
// Android doesn't need to do anything.
|
|
|
|
|
|
|
|
#endif // CC_PLATFORM_ANDROID
|
|
|
|
|
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WOPHONE)
|
2011-03-01 14:28:39 +08:00
|
|
|
// Initialize OpenGLView instance, that release by CCDirector when application terminate.
|
|
|
|
// The HelloWorld is designed as HVGA.
|
2011-03-09 15:35:06 +08:00
|
|
|
// Use GetScreenWidth() and GetScreenHeight() get screen width and height.
|
|
|
|
CCEGLView * pMainWnd = new CCEGLView(this);
|
|
|
|
CC_BREAK_IF(! pMainWnd
|
2011-03-12 10:24:36 +08:00
|
|
|
|| ! pMainWnd->Create(320, 480));
|
|
|
|
|
|
|
|
#if !defined(_TRANZDA_VM_)
|
|
|
|
// set the resource zip file
|
|
|
|
// on wophone emulator, we copy resources files to Work7/TG3/APP/ folder instead of zip file
|
|
|
|
CCFileUtils::setResource("[!output PROJECT_NAME].zip");
|
|
|
|
#endif
|
2011-03-01 14:28:39 +08:00
|
|
|
|
2011-03-17 11:27:51 +08:00
|
|
|
#endif // CC_PLATFORM_WOPHONE
|
|
|
|
|
2011-03-01 14:28:39 +08:00
|
|
|
bRet = true;
|
|
|
|
} while (0);
|
|
|
|
return bRet;
|
|
|
|
}
|
2010-11-16 11:25:33 +08:00
|
|
|
|
2011-03-01 14:28:39 +08:00
|
|
|
bool AppDelegate::applicationDidFinishLaunching()
|
|
|
|
{
|
|
|
|
// initialize director
|
|
|
|
CCDirector *pDirector = CCDirector::sharedDirector();
|
2011-03-09 15:35:06 +08:00
|
|
|
pDirector->setOpenGLView(&CCEGLView::sharedOpenGLView());
|
2011-03-01 14:28:39 +08:00
|
|
|
|
|
|
|
// sets landscape mode
|
2010-11-16 11:25:33 +08:00
|
|
|
pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
|
2011-03-01 14:28:39 +08:00
|
|
|
|
|
|
|
// turn on display FPS
|
2010-11-16 11:25:33 +08:00
|
|
|
pDirector->setDisplayFPS(true);
|
|
|
|
|
2011-03-01 14:28:39 +08:00
|
|
|
// set FPS. the default value is 1.0/60 if you don't call this
|
|
|
|
pDirector->setAnimationInterval(1.0 / 60);
|
2010-11-16 11:25:33 +08:00
|
|
|
|
2011-03-01 14:28:39 +08:00
|
|
|
// create a scene. it's an autorelease object
|
|
|
|
CCScene *pScene = HelloWorld::scene();
|
2010-11-16 11:25:33 +08:00
|
|
|
|
2011-03-01 14:28:39 +08:00
|
|
|
// run
|
2011-01-18 15:32:29 +08:00
|
|
|
pDirector->runWithScene(pScene);
|
2010-11-16 11:25:33 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-01-18 15:32:29 +08:00
|
|
|
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
2010-11-16 11:25:33 +08:00
|
|
|
void AppDelegate::applicationDidEnterBackground()
|
|
|
|
{
|
2010-12-03 15:27:55 +08:00
|
|
|
CCDirector::sharedDirector()->pause();
|
2011-03-09 15:35:06 +08:00
|
|
|
[! if CC_USE_COCOS_DENSHION_SIMPLE_AUDIO_ENGINE]
|
2010-12-03 15:27:55 +08:00
|
|
|
|
|
|
|
SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
|
|
|
|
[! endif]
|
2010-11-16 11:25:33 +08:00
|
|
|
}
|
|
|
|
|
2011-01-18 15:32:29 +08:00
|
|
|
// this function will be called when the app is active again
|
2010-11-16 11:25:33 +08:00
|
|
|
void AppDelegate::applicationWillEnterForeground()
|
|
|
|
{
|
2010-12-03 15:27:55 +08:00
|
|
|
CCDirector::sharedDirector()->resume();
|
2011-03-09 15:35:06 +08:00
|
|
|
[! if CC_USE_COCOS_DENSHION_SIMPLE_AUDIO_ENGINE]
|
2010-12-03 15:27:55 +08:00
|
|
|
|
|
|
|
SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
|
|
|
|
[! endif]
|
2010-11-16 11:25:33 +08:00
|
|
|
}
|