2012-04-19 14:35:52 +08:00
|
|
|
#include "AppDelegate.h"
|
|
|
|
|
|
|
|
#include "cocos2d.h"
|
2012-07-19 17:22:36 +08:00
|
|
|
#include "controller.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
#include "SimpleAudioEngine.h"
|
|
|
|
|
|
|
|
USING_NS_CC;
|
|
|
|
using namespace CocosDenshion;
|
|
|
|
|
|
|
|
AppDelegate::AppDelegate()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
AppDelegate::~AppDelegate()
|
|
|
|
{
|
|
|
|
// SimpleAudioEngine::end();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AppDelegate::applicationDidFinishLaunching()
|
|
|
|
{
|
|
|
|
// initialize director
|
|
|
|
CCDirector *pDirector = CCDirector::sharedDirector();
|
2012-08-21 14:58:31 +08:00
|
|
|
pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-08-23 14:20:32 +08:00
|
|
|
TargetPlatform target = getTargetPlatform();
|
|
|
|
|
|
|
|
if (target == kTargetIpad)
|
|
|
|
{
|
|
|
|
// ipad
|
|
|
|
|
|
|
|
if (pDirector->enableRetinaDisplay(true))
|
|
|
|
{
|
|
|
|
// ipad hd
|
|
|
|
CCFileUtils::sharedFileUtils()->setResourceDirectory("ipadhd");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CCFileUtils::sharedFileUtils()->setResourceDirectory("ipad");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (target == kTargetIphone)
|
|
|
|
{
|
|
|
|
// iphone
|
|
|
|
|
|
|
|
if (pDirector->enableRetinaDisplay(true))
|
|
|
|
{
|
|
|
|
// iphone hd
|
|
|
|
CCFileUtils::sharedFileUtils()->setResourceDirectory("hd");
|
|
|
|
}
|
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// turn on display FPS
|
|
|
|
pDirector->setDisplayStats(true);
|
|
|
|
|
|
|
|
// set FPS. the default value is 1.0/60 if you don't call this
|
|
|
|
pDirector->setAnimationInterval(1.0 / 60);
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCScene * pScene = CCScene::create();
|
2012-04-19 14:35:52 +08:00
|
|
|
CCLayer * pLayer = new TestController();
|
|
|
|
pLayer->autorelease();
|
|
|
|
|
|
|
|
pScene->addChild(pLayer);
|
|
|
|
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()
|
|
|
|
{
|
2012-06-21 11:42:49 +08:00
|
|
|
CCDirector::sharedDirector()->stopAnimation();
|
2012-04-19 14:35:52 +08:00
|
|
|
SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
|
|
|
|
SimpleAudioEngine::sharedEngine()->pauseAllEffects();
|
|
|
|
}
|
|
|
|
|
|
|
|
// this function will be called when the app is active again
|
|
|
|
void AppDelegate::applicationWillEnterForeground()
|
|
|
|
{
|
2012-06-21 11:42:49 +08:00
|
|
|
CCDirector::sharedDirector()->startAnimation();
|
2012-04-19 14:35:52 +08:00
|
|
|
SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
|
|
|
|
SimpleAudioEngine::sharedEngine()->resumeAllEffects();
|
|
|
|
}
|