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-05-18 11:08:18 +08:00
|
|
|
#include "SimpleAudioEngine.h"
|
2010-11-12 16:25:14 +08:00
|
|
|
|
2011-01-22 17:30:00 +08:00
|
|
|
USING_NS_CC;
|
2011-05-18 11:08:18 +08:00
|
|
|
using namespace CocosDenshion;
|
2010-11-12 16:25:14 +08:00
|
|
|
|
|
|
|
AppDelegate::AppDelegate()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
AppDelegate::~AppDelegate()
|
|
|
|
{
|
2011-05-24 18:00:59 +08:00
|
|
|
SimpleAudioEngine::end();
|
2010-11-12 16:25:14 +08:00
|
|
|
}
|
|
|
|
|
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-04-27 18:19:47 +08:00
|
|
|
|| ! pMainWnd->Create(TEXT("cocos2d: tests"), 480, 320));
|
2011-02-18 18:30:22 +08:00
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
#endif // CC_PLATFORM_WIN32
|
2011-05-30 14:14:19 +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-05-30 14:14:19 +08:00
|
|
|
|
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-05-30 14:14:19 +08:00
|
|
|
|
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);
|
2011-05-06 16:38:09 +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("TestCocos2dx.zip");
|
2011-05-18 11:08:18 +08:00
|
|
|
CocosDenshion::SimpleAudioEngine::setResource("TestCocos2dx.zip");
|
2011-03-02 17:45:04 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
2011-05-30 14:14:19 +08:00
|
|
|
|
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_AIRPLAY)
|
|
|
|
CCDirector::sharedDirector()->setDeviceOrientation(CCDeviceOrientationLandscapeLeft);
|
|
|
|
#endif
|
|
|
|
|
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-04-26 18:04:07 +08:00
|
|
|
// sets opengl landscape mode
|
2011-05-03 11:37:30 +08:00
|
|
|
// tests set device orientation in RootViewController.mm
|
2011-04-26 18:04:07 +08:00
|
|
|
// 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();
|
2011-05-18 11:08:18 +08:00
|
|
|
SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
|
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();
|
2011-05-18 11:08:18 +08:00
|
|
|
SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
|
2010-11-12 16:25:14 +08:00
|
|
|
}
|