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"
|
2013-10-16 11:19:01 +08:00
|
|
|
#include "cocostudio/CocoStudio.h"
|
2013-10-16 16:48:39 +08:00
|
|
|
#include "extensions/cocos-ext.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
USING_NS_CC;
|
|
|
|
using namespace CocosDenshion;
|
|
|
|
|
|
|
|
AppDelegate::AppDelegate()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
AppDelegate::~AppDelegate()
|
|
|
|
{
|
|
|
|
// SimpleAudioEngine::end();
|
2013-12-27 20:54:05 +08:00
|
|
|
cocostudio::ArmatureDataManager::destroyInstance();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AppDelegate::applicationDidFinishLaunching()
|
|
|
|
{
|
2013-06-07 03:23:44 +08:00
|
|
|
// As an example, load config file
|
|
|
|
// XXX: This should be loaded before the Director is initialized,
|
|
|
|
// XXX: but at this point, the director is already initialized
|
2013-07-12 06:24:23 +08:00
|
|
|
Configuration::getInstance()->loadConfigFile("configs/config-example.plist");
|
2013-06-07 03:23:44 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// initialize director
|
2013-08-16 16:05:27 +08:00
|
|
|
auto director = Director::getInstance();
|
2013-07-23 08:25:44 +08:00
|
|
|
director->setOpenGLView(EGLView::getInstance());
|
|
|
|
|
|
|
|
director->setDisplayStats(true);
|
|
|
|
director->setAnimationInterval(1.0 / 60);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto screenSize = EGLView::getInstance()->getFrameSize();
|
2012-08-23 14:20:32 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto designSize = Size(480, 320);
|
2013-06-09 18:54:35 +08:00
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto pFileUtils = FileUtils::getInstance();
|
2013-09-14 19:03:15 +08:00
|
|
|
std::vector<std::string> searchPaths;
|
2012-10-23 17:48:50 +08:00
|
|
|
|
|
|
|
if (screenSize.height > 320)
|
2012-10-12 17:37:26 +08:00
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto resourceSize = Size(960, 640);
|
2013-01-28 17:44:53 +08:00
|
|
|
searchPaths.push_back("hd");
|
2013-09-14 16:34:26 +08:00
|
|
|
searchPaths.push_back("hd/scenetest");
|
2014-01-03 02:21:36 +08:00
|
|
|
searchPaths.push_back("hd/scenetest/ArmatureComponentTest");
|
|
|
|
searchPaths.push_back("hd/scenetest/AttributeComponentTest");
|
|
|
|
searchPaths.push_back("hd/scenetest/BackgroundComponentTest");
|
|
|
|
searchPaths.push_back("hd/scenetest/EffectComponentTest");
|
2014-01-06 14:49:32 +08:00
|
|
|
searchPaths.push_back("hd/scenetest/LoadSceneEdtiorFileTest");
|
2014-01-03 02:21:36 +08:00
|
|
|
searchPaths.push_back("hd/scenetest/ParticleComponentTest");
|
|
|
|
searchPaths.push_back("hd/scenetest/SpriteComponentTest");
|
|
|
|
searchPaths.push_back("hd/scenetest/TmxMapComponentTest");
|
|
|
|
searchPaths.push_back("hd/scenetest/UIComponentTest");
|
|
|
|
searchPaths.push_back("hd/scenetest/TriggerTest");
|
2013-07-23 08:25:44 +08:00
|
|
|
director->setContentScaleFactor(resourceSize.height/designSize.height);
|
2012-10-12 17:37:26 +08:00
|
|
|
}
|
2013-09-14 19:03:15 +08:00
|
|
|
else
|
|
|
|
{
|
2014-01-03 02:21:36 +08:00
|
|
|
searchPaths.push_back("scenetest/ArmatureComponentTest");
|
|
|
|
searchPaths.push_back("scenetest/AttributeComponentTest");
|
|
|
|
searchPaths.push_back("scenetest/BackgroundComponentTest");
|
|
|
|
searchPaths.push_back("scenetest/EffectComponentTest");
|
2014-01-06 14:49:32 +08:00
|
|
|
searchPaths.push_back("scenetest/LoadSceneEdtiorFileTest");
|
2014-01-03 02:21:36 +08:00
|
|
|
searchPaths.push_back("scenetest/ParticleComponentTest");
|
|
|
|
searchPaths.push_back("scenetest/SpriteComponentTest");
|
|
|
|
searchPaths.push_back("scenetest/TmxMapComponentTest");
|
|
|
|
searchPaths.push_back("scenetest/UIComponentTest");
|
|
|
|
searchPaths.push_back("scenetest/TriggerTest");
|
2013-09-14 19:03:15 +08:00
|
|
|
}
|
2013-10-16 11:19:01 +08:00
|
|
|
|
2013-09-14 19:03:15 +08:00
|
|
|
pFileUtils->setSearchPaths(searchPaths);
|
2012-10-12 17:37:26 +08:00
|
|
|
|
2013-07-26 18:18:58 +08:00
|
|
|
EGLView::getInstance()->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::NO_BORDER);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
auto scene = Scene::create();
|
|
|
|
auto layer = new TestController();
|
|
|
|
layer->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
scene->addChild(layer);
|
|
|
|
director->runWithScene(scene);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->stopAnimation();
|
2013-07-19 07:30:19 +08:00
|
|
|
SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
|
|
|
|
SimpleAudioEngine::getInstance()->pauseAllEffects();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// this function will be called when the app is active again
|
|
|
|
void AppDelegate::applicationWillEnterForeground()
|
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->startAnimation();
|
2013-07-19 07:30:19 +08:00
|
|
|
SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
|
|
|
|
SimpleAudioEngine::getInstance()->resumeAllEffects();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|