2011-01-22 16:24:54 +08:00
|
|
|
#include "AppDelegate.h"
|
2010-11-27 18:25:31 +08:00
|
|
|
|
|
|
|
#include "cocos2d.h"
|
|
|
|
#include "HelloWorldScene.h"
|
|
|
|
|
2011-03-01 12:41:57 +08:00
|
|
|
USING_NS_CC;
|
|
|
|
|
2010-11-27 18:25:31 +08:00
|
|
|
AppDelegate::AppDelegate()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
AppDelegate::~AppDelegate()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-03-01 12:41:57 +08:00
|
|
|
bool AppDelegate::initInstance()
|
2010-11-27 18:25:31 +08:00
|
|
|
{
|
2011-03-01 12:41:57 +08:00
|
|
|
bool bRet = false;
|
|
|
|
do
|
2011-01-19 14:23:26 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
2011-03-01 12:41:57 +08:00
|
|
|
|
|
|
|
// Initialize OpenGLView instance, that release by CCDirector when application terminate.
|
|
|
|
// The HelloWorld is designed as HVGA.
|
2011-03-07 17:11:57 +08:00
|
|
|
CCEGLView * pMainWnd = new CCEGLView();
|
|
|
|
CC_BREAK_IF(! pMainWnd
|
2011-05-24 18:13:54 +08:00
|
|
|
|| ! pMainWnd->Create(TEXT("cocos2d: Hello World"), 480, 320));
|
2010-11-27 18:25:31 +08:00
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
#endif // CC_PLATFORM_WIN32
|
2011-03-02 17:05:22 +08:00
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
2011-03-17 11:27:51 +08:00
|
|
|
|
2011-03-02 17:05:22 +08:00
|
|
|
// OpenGLView initialized in testsAppDelegate.mm on ios platform, nothing need to do here.
|
2011-03-17 11:27:51 +08:00
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
#endif // CC_PLATFORM_IOS
|
2011-03-02 17:05:22 +08:00
|
|
|
|
2011-03-17 11:27:51 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
|
|
|
|
2011-05-26 10:08:05 +08:00
|
|
|
// OpenGLView initialized in HelloWorld/android/jni/helloworld/main.cpp
|
|
|
|
// the default setting is to create a fullscreen view
|
|
|
|
// if you want to use auto-scale, please enable view->create(320,480) in main.cpp
|
2011-03-17 11:27:51 +08:00
|
|
|
|
|
|
|
#endif // CC_PLATFORM_ANDROID
|
|
|
|
|
2011-03-09 17:28:35 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WOPHONE)
|
2011-03-02 17:45:04 +08:00
|
|
|
|
|
|
|
// Initialize OpenGLView instance, that release by CCDirector when application terminate.
|
|
|
|
// The HelloWorld is designed as HVGA.
|
2011-03-07 17:11:57 +08:00
|
|
|
CCEGLView* pMainWnd = new CCEGLView(this);
|
2011-05-24 18:13:54 +08:00
|
|
|
CC_BREAK_IF(! pMainWnd || ! pMainWnd->Create(320,480, WM_WINDOW_ROTATE_MODE_CW));
|
2011-03-02 17:45:04 +08:00
|
|
|
|
|
|
|
#ifndef _TRANZDA_VM_
|
2011-04-22 10:57:46 +08:00
|
|
|
// on wophone emulator, we copy resources files to Work7/NEWPLUS/TDA_DATA/Data/ folder instead of zip file
|
2011-03-02 17:45:04 +08:00
|
|
|
cocos2d::CCFileUtils::setResource("HelloWorld.zip");
|
|
|
|
#endif
|
|
|
|
|
2011-03-09 17:28:35 +08:00
|
|
|
#endif // CC_PLATFORM_WOPHONE
|
2011-03-02 17:45:04 +08:00
|
|
|
|
2011-05-30 14:14:19 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_AIRPLAY)
|
|
|
|
// MaxAksenov said it's NOT a very elegant solution. I agree, haha
|
|
|
|
CCDirector::sharedDirector()->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
|
|
|
|
#endif
|
2011-03-01 12:41:57 +08:00
|
|
|
bRet = true;
|
|
|
|
} while (0);
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AppDelegate::applicationDidFinishLaunching()
|
|
|
|
{
|
|
|
|
// initialize director
|
2010-11-27 18:25:31 +08:00
|
|
|
CCDirector *pDirector = CCDirector::sharedDirector();
|
2011-03-07 17:11:57 +08:00
|
|
|
pDirector->setOpenGLView(&CCEGLView::sharedOpenGLView());
|
2011-02-18 18:30:22 +08:00
|
|
|
|
|
|
|
// enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices.
|
|
|
|
// pDirector->enableRetinaDisplay(true);
|
2010-11-27 18:25:31 +08:00
|
|
|
|
|
|
|
// turn on display FPS
|
|
|
|
pDirector->setDisplayFPS(true);
|
|
|
|
|
2011-05-24 18:13:54 +08:00
|
|
|
// pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
|
|
|
|
|
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();
|
|
|
|
}
|