2014-01-31 07:11:54 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 cocos2d-x.org
|
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
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"
|
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;
|
|
|
|
|
|
|
|
AppDelegate::AppDelegate()
|
2014-02-20 21:49:13 +08:00
|
|
|
:_curTest(nullptr)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
AppDelegate::~AppDelegate()
|
|
|
|
{
|
|
|
|
// SimpleAudioEngine::end();
|
2014-01-25 05:43:46 +08:00
|
|
|
cocostudio::ArmatureDataManager::destroyInstance();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool AppDelegate::applicationDidFinishLaunching()
|
|
|
|
{
|
2014-01-25 05:43:46 +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
|
|
|
|
Configuration::getInstance()->loadConfigFile("configs/config-example.plist");
|
2014-01-24 07:36:55 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// initialize director
|
2013-08-16 16:05:27 +08:00
|
|
|
auto director = Director::getInstance();
|
2014-01-25 05:43:46 +08:00
|
|
|
auto glview = director->getOpenGLView();
|
|
|
|
if(!glview) {
|
2014-03-11 17:34:08 +08:00
|
|
|
glview = GLView::create("Cpp Tests");
|
2014-01-25 05:43:46 +08:00
|
|
|
director->setOpenGLView(glview);
|
|
|
|
}
|
2013-07-23 08:25:44 +08:00
|
|
|
|
|
|
|
director->setDisplayStats(true);
|
|
|
|
director->setAnimationInterval(1.0 / 60);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2014-01-24 07:36:55 +08:00
|
|
|
auto screenSize = glview->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
|
|
|
|
2014-01-28 11:16:09 +08:00
|
|
|
auto fileUtils = FileUtils::getInstance();
|
2014-01-25 05:43:46 +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");
|
2014-03-07 18:24:40 +08:00
|
|
|
searchPaths.push_back("hd/scenetest");
|
|
|
|
searchPaths.push_back("hd/scenetest/ArmatureComponentTest");
|
|
|
|
searchPaths.push_back("hd/scenetest/AttributeComponentTest");
|
|
|
|
searchPaths.push_back("hd/scenetest/BackgroundComponentTest");
|
|
|
|
searchPaths.push_back("hd/scenetest/EffectComponentTest");
|
|
|
|
searchPaths.push_back("hd/scenetest/LoadSceneEdtiorFileTest");
|
|
|
|
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
|
|
|
}
|
2014-01-25 05:43:46 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
searchPaths.push_back("scenetest/ArmatureComponentTest");
|
|
|
|
searchPaths.push_back("scenetest/AttributeComponentTest");
|
|
|
|
searchPaths.push_back("scenetest/BackgroundComponentTest");
|
|
|
|
searchPaths.push_back("scenetest/EffectComponentTest");
|
|
|
|
searchPaths.push_back("scenetest/LoadSceneEdtiorFileTest");
|
|
|
|
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-10-16 11:19:01 +08:00
|
|
|
|
2014-01-28 11:16:09 +08:00
|
|
|
fileUtils->setSearchPaths(searchPaths);
|
2012-10-12 17:37:26 +08:00
|
|
|
|
2014-03-22 21:16:43 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
2014-03-29 02:28:48 +08:00
|
|
|
// a bug in DirectX 11 level9-x on the device prevents ResolutionPolicy::NO_BORDER from working correctly
|
2014-03-22 21:16:43 +08:00
|
|
|
glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::SHOW_ALL);
|
|
|
|
#else
|
2014-01-24 07:36:55 +08:00
|
|
|
glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::NO_BORDER);
|
2014-03-22 21:16:43 +08:00
|
|
|
#endif
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
auto scene = Scene::create();
|
|
|
|
auto layer = new TestController();
|
2014-03-22 21:16:43 +08:00
|
|
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WP8) && (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
|
2014-02-19 16:13:32 +08:00
|
|
|
layer->addConsoleAutoTest();
|
2014-03-22 21:16:43 +08:00
|
|
|
#endif
|
|
|
|
|
2013-07-23 08:25:44 +08:00
|
|
|
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
|
|
|
|
2014-01-11 12:32:39 +08:00
|
|
|
// Enable Remote Console
|
2014-04-20 01:08:01 +08:00
|
|
|
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
|
2014-01-11 12:32:39 +08:00
|
|
|
auto console = director->getConsole();
|
|
|
|
console->listenOnTCP(5678);
|
2014-03-22 21:16:43 +08:00
|
|
|
#endif
|
2014-01-11 12:32:39 +08:00
|
|
|
|
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();
|
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();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2014-02-20 21:49:13 +08:00
|
|
|
|
|
|
|
void AppDelegate::setCurrentTest(BaseTest* curTest)
|
|
|
|
{
|
|
|
|
_curTest = curTest;
|
|
|
|
}
|
|
|
|
|
|
|
|
BaseTest* AppDelegate::getCurrentTest()
|
|
|
|
{
|
|
|
|
return _curTest;
|
|
|
|
}
|