2010-11-12 16:25:14 +08:00
|
|
|
#include "AppDelegate.h"
|
2011-01-22 17:30:00 +08:00
|
|
|
|
2010-11-12 16:25:14 +08:00
|
|
|
#include "cocos2d.h"
|
|
|
|
#include "tests/controller.h"
|
|
|
|
|
2011-01-22 17:30:00 +08:00
|
|
|
USING_NS_CC;
|
2010-11-12 16:25:14 +08:00
|
|
|
|
|
|
|
AppDelegate::AppDelegate()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
AppDelegate::~AppDelegate()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-03-01 12:41:57 +08:00
|
|
|
bool AppDelegate::initInstance()
|
2010-11-12 16:25:14 +08:00
|
|
|
{
|
2011-03-01 12:41:57 +08:00
|
|
|
bool bRet = false;
|
|
|
|
do
|
2011-02-18 18:30:22 +08:00
|
|
|
{
|
2011-03-07 17:11:57 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
2011-02-18 18:30:22 +08:00
|
|
|
|
2011-03-01 12:41:57 +08:00
|
|
|
// Initialize OpenGLView instance, that release by CCDirector when application terminate.
|
|
|
|
// The tests is designed as HVGA.
|
2011-03-07 17:11:57 +08:00
|
|
|
CCEGLView * pMainWnd = new CCEGLView();
|
|
|
|
CC_BREAK_IF(! pMainWnd
|
2011-03-01 12:41:57 +08:00
|
|
|
|| ! pMainWnd->Create(TEXT("cocos2d: tests"), 320, 480));
|
2011-02-18 18:30:22 +08:00
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
#endif // CC_PLATFORM_WIN32
|
2011-03-04 17:17:53 +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-17 11:27:51 +08:00
|
|
|
|
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
|
|
|
|
|
|
|
// Android doesn't need to do anything.
|
|
|
|
|
|
|
|
#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 tests is designed as HVGA.
|
2011-03-07 17:11:57 +08:00
|
|
|
CCEGLView* pMainWnd = new CCEGLView(this);
|
|
|
|
CC_BREAK_IF(! pMainWnd || ! pMainWnd->Create(320,480));
|
2011-03-02 17:45:04 +08:00
|
|
|
|
|
|
|
#ifndef _TRANZDA_VM_
|
2011-03-09 17:28:35 +08:00
|
|
|
// on wophone emulator, we copy resources files to Work7/TG3/APP/ folder instead of zip file
|
2011-03-02 17:45:04 +08:00
|
|
|
cocos2d::CCFileUtils::setResource("TestCocos2dx.zip");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
2011-03-04 17:17:53 +08:00
|
|
|
|
2011-03-01 12:41:57 +08:00
|
|
|
bRet = true;
|
|
|
|
} while (0);
|
|
|
|
return bRet;
|
|
|
|
}
|
2011-02-18 18:30:22 +08:00
|
|
|
|
2011-03-01 12:41:57 +08:00
|
|
|
bool AppDelegate::applicationDidFinishLaunching()
|
|
|
|
{
|
2011-03-02 17:05:22 +08:00
|
|
|
// initialize director
|
|
|
|
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.
|
2011-03-02 17:05:22 +08:00
|
|
|
// pDirector->enableRetinaDisplay(true);
|
2011-02-18 18:30:22 +08:00
|
|
|
|
2011-03-02 17:05:22 +08:00
|
|
|
// sets landscape mode
|
|
|
|
pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
|
2011-02-18 18:30:22 +08:00
|
|
|
|
2011-03-01 12:41:57 +08:00
|
|
|
// turn on display FPS
|
2010-11-19 11:14:19 +08:00
|
|
|
pDirector->setDisplayFPS(true);
|
2010-11-12 16:25:14 +08:00
|
|
|
|
2011-02-18 18:30:22 +08:00
|
|
|
// set FPS. the default value is 1.0/60 if you don't call this
|
|
|
|
pDirector->setAnimationInterval(1.0 / 60);
|
|
|
|
|
2010-11-12 16:25:14 +08:00
|
|
|
CCScene * pScene = CCScene::node();
|
|
|
|
CCLayer * pLayer = new TestController();
|
|
|
|
pLayer->autorelease();
|
|
|
|
|
|
|
|
pScene->addChild(pLayer);
|
|
|
|
pDirector->runWithScene(pScene);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-03-01 12:41:57 +08:00
|
|
|
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
2010-11-12 16:25:14 +08:00
|
|
|
void AppDelegate::applicationDidEnterBackground()
|
|
|
|
{
|
2010-12-02 18:44:13 +08:00
|
|
|
CCDirector::sharedDirector()->pause();
|
2010-11-12 16:25:14 +08:00
|
|
|
}
|
|
|
|
|
2011-03-01 12:41:57 +08:00
|
|
|
// this function will be called when the app is active again
|
2010-11-12 16:25:14 +08:00
|
|
|
void AppDelegate::applicationWillEnterForeground()
|
|
|
|
{
|
2010-12-02 18:44:13 +08:00
|
|
|
CCDirector::sharedDirector()->resume();
|
2010-11-12 16:25:14 +08:00
|
|
|
}
|