2013-09-20 22:23:13 +08:00
|
|
|
|
2013-10-16 16:48:39 +08:00
|
|
|
#include "extensions/cocos-ext.h"
|
2013-09-20 22:23:13 +08:00
|
|
|
#include "../ExtensionsTest.h"
|
|
|
|
#include "SceneEditorTest.h"
|
2013-10-16 11:19:01 +08:00
|
|
|
#include "cocostudio/CocoStudio.h"
|
2014-03-11 17:13:54 +08:00
|
|
|
#include "ui/CocosGUI.h"
|
2013-12-26 01:17:04 +08:00
|
|
|
#include "TriggerCode/EventDef.h"
|
2014-01-03 01:14:12 +08:00
|
|
|
#include "../../testResource.h"
|
2013-09-20 22:23:13 +08:00
|
|
|
|
|
|
|
using namespace cocos2d;
|
2013-10-15 18:00:03 +08:00
|
|
|
using namespace cocostudio;
|
2014-02-24 18:56:45 +08:00
|
|
|
using namespace ui;
|
2013-09-20 22:23:13 +08:00
|
|
|
|
2014-01-03 01:14:12 +08:00
|
|
|
Layer *Next();
|
|
|
|
Layer *Back();
|
|
|
|
Layer *Restart();
|
|
|
|
|
|
|
|
static int s_nIdx = -1;
|
|
|
|
|
|
|
|
Layer *createTests(int index)
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
2014-01-03 01:14:12 +08:00
|
|
|
Layer *layer = nullptr;
|
|
|
|
switch(index)
|
|
|
|
{
|
|
|
|
case TEST_LOADSCENEEDITORFILE:
|
2014-01-03 20:33:07 +08:00
|
|
|
layer = new LoadSceneEdtiorFileTest();
|
2014-01-03 01:14:12 +08:00
|
|
|
break;
|
|
|
|
case TEST_SPIRTECOMPONENT:
|
|
|
|
layer = new SpriteComponentTest();
|
|
|
|
break;
|
|
|
|
case TEST_ARMATURECOMPONENT:
|
|
|
|
layer = new ArmatureComponentTest();
|
|
|
|
break;
|
|
|
|
case TEST_UICOMPONENT:
|
|
|
|
layer = new UIComponentTest();
|
|
|
|
break;
|
|
|
|
case TEST_TMXMAPCOMPONENT:
|
|
|
|
layer = new TmxMapComponentTest();
|
|
|
|
break;
|
|
|
|
case TEST_PARTICLECOMPONENT:
|
|
|
|
layer = new ParticleComponentTest();
|
|
|
|
break;
|
|
|
|
case TEST_EFEECTCOMPONENT:
|
|
|
|
layer = new EffectComponentTest();
|
|
|
|
break;
|
|
|
|
case TEST_BACKGROUNDCOMPONENT:
|
|
|
|
layer = new BackgroundComponentTest();
|
|
|
|
break;
|
|
|
|
case TEST_ATTRIBUTECOMPONENT:
|
|
|
|
layer = new AttributeComponentTest();
|
|
|
|
break;
|
|
|
|
case TEST_TRIGGER:
|
|
|
|
layer = new TriggerTest();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return layer;
|
|
|
|
}
|
|
|
|
|
|
|
|
Layer *Next()
|
|
|
|
{
|
|
|
|
++s_nIdx;
|
|
|
|
s_nIdx = s_nIdx % TEST_SCENEEDITOR_COUNT;
|
|
|
|
|
|
|
|
Layer *layer = createTests(s_nIdx);
|
|
|
|
layer->autorelease();
|
|
|
|
|
|
|
|
return layer;
|
|
|
|
}
|
|
|
|
|
|
|
|
Layer *Back()
|
|
|
|
{
|
|
|
|
--s_nIdx;
|
|
|
|
if( s_nIdx < 0 )
|
|
|
|
s_nIdx += TEST_SCENEEDITOR_COUNT;
|
|
|
|
|
|
|
|
Layer *layer = createTests(s_nIdx);
|
|
|
|
layer->autorelease();
|
|
|
|
|
|
|
|
return layer;
|
|
|
|
}
|
|
|
|
|
|
|
|
Layer *Restart()
|
|
|
|
{
|
|
|
|
Layer *layer = createTests(s_nIdx);
|
|
|
|
layer->autorelease();
|
|
|
|
|
|
|
|
return layer;
|
|
|
|
}
|
|
|
|
|
|
|
|
SceneEditorTestScene::SceneEditorTestScene(bool bPortrait)
|
|
|
|
{
|
|
|
|
TestScene::init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SceneEditorTestScene::runThisTest()
|
|
|
|
{
|
|
|
|
s_nIdx = -1;
|
|
|
|
addChild(Next());
|
|
|
|
CCDirector::getInstance()->replaceScene(this);
|
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void SceneEditorTestScene::MainMenuCallback(Ref *pSender)
|
2014-01-03 01:14:12 +08:00
|
|
|
{
|
|
|
|
removeAllChildren();
|
|
|
|
}
|
|
|
|
|
2014-06-26 10:08:17 +08:00
|
|
|
const char* SceneEditorTestLayer::_loadtypeStr[2] = {"change to load \nwith binary file","change to load \nwith json file"};
|
2014-01-03 01:14:12 +08:00
|
|
|
void SceneEditorTestLayer::onEnter()
|
|
|
|
{
|
|
|
|
CCLayer::onEnter();
|
|
|
|
|
|
|
|
// add title and subtitle
|
|
|
|
std::string str = title();
|
|
|
|
const char *pTitle = str.c_str();
|
2014-04-09 23:31:05 +08:00
|
|
|
auto label = Label::createWithTTF(pTitle, "fonts/arial.ttf", 18);
|
2014-03-26 23:33:58 +08:00
|
|
|
label->setTextColor(Color4B::WHITE);
|
2014-01-03 01:14:12 +08:00
|
|
|
addChild(label, 1, 10000);
|
2014-05-15 01:07:09 +08:00
|
|
|
label->setPosition( Vec2(VisibleRect::center().x, VisibleRect::top().y - 30) );
|
2014-01-03 01:14:12 +08:00
|
|
|
|
|
|
|
std::string strSubtitle = subtitle();
|
|
|
|
if( ! strSubtitle.empty() )
|
|
|
|
{
|
2014-04-09 23:31:05 +08:00
|
|
|
auto l = Label::createWithTTF(strSubtitle.c_str(), "fonts/arial.ttf", 18);
|
2014-03-26 23:33:58 +08:00
|
|
|
l->setTextColor(Color4B::BLACK);
|
2014-01-03 01:14:12 +08:00
|
|
|
addChild(l, 1, 10001);
|
2014-05-15 01:07:09 +08:00
|
|
|
l->setPosition(Vec2(VisibleRect::center().x, VisibleRect::top().y - 60) );
|
2014-01-03 01:14:12 +08:00
|
|
|
}
|
2014-06-26 10:08:17 +08:00
|
|
|
_isCsbLoad = false;
|
|
|
|
_loadtypelb = cocos2d::Label::createWithSystemFont(_loadtypeStr[0], "Arial", 12);
|
2014-06-25 14:32:38 +08:00
|
|
|
// #endif
|
2014-06-26 10:08:17 +08:00
|
|
|
MenuItemLabel* itemlb = CCMenuItemLabel::create(_loadtypelb, CC_CALLBACK_1(SceneEditorTestLayer::changeLoadTypeCallback, this));
|
2014-07-10 00:45:27 +08:00
|
|
|
Menu* loadtypemenu = CCMenu::create(itemlb, nullptr);
|
2014-06-25 14:32:38 +08:00
|
|
|
loadtypemenu->setPosition(Point(VisibleRect::rightTop().x -50,VisibleRect::rightTop().y -20));
|
|
|
|
addChild(loadtypemenu,100);
|
2014-01-03 01:14:12 +08:00
|
|
|
|
|
|
|
// add menu
|
|
|
|
backItem = MenuItemImage::create(s_pathB1, s_pathB2, CC_CALLBACK_1(SceneEditorTestLayer::backCallback, this) );
|
|
|
|
restartItem = MenuItemImage::create(s_pathR1, s_pathR2, CC_CALLBACK_1(SceneEditorTestLayer::restartCallback, this) );
|
|
|
|
nextItem = MenuItemImage::create(s_pathF1, s_pathF2, CC_CALLBACK_1(SceneEditorTestLayer::nextCallback, this) );
|
|
|
|
|
|
|
|
|
|
|
|
Menu *menu = Menu::create(backItem, restartItem, nextItem, nullptr);
|
|
|
|
|
|
|
|
float fScale = 0.5f;
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
menu->setPosition(Vec2(0, 0));
|
|
|
|
backItem->setPosition(Vec2(VisibleRect::center().x - restartItem->getContentSize().width * 2 * fScale, VisibleRect::bottom().y + restartItem->getContentSize().height / 2));
|
2014-01-03 01:14:12 +08:00
|
|
|
backItem->setScale(fScale);
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
restartItem->setPosition(Vec2(VisibleRect::center().x, VisibleRect::bottom().y + restartItem->getContentSize().height / 2));
|
2014-01-03 01:14:12 +08:00
|
|
|
restartItem->setScale(fScale);
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
nextItem->setPosition(Vec2(VisibleRect::center().x + restartItem->getContentSize().width * 2 * fScale, VisibleRect::bottom().y + restartItem->getContentSize().height / 2));
|
2014-01-03 01:14:12 +08:00
|
|
|
nextItem->setScale(fScale);
|
|
|
|
|
|
|
|
addChild(menu, 100);
|
|
|
|
|
2014-05-13 10:12:56 +08:00
|
|
|
setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR));
|
2014-01-03 01:14:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void SceneEditorTestLayer::onExit()
|
|
|
|
{
|
|
|
|
removeAllChildren();
|
|
|
|
backItem = restartItem = nextItem = nullptr;
|
|
|
|
Layer::onExit();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SceneEditorTestLayer::title()
|
|
|
|
{
|
|
|
|
return "SceneReader Test LoadSceneEditorFile";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string SceneEditorTestLayer::subtitle()
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void SceneEditorTestLayer::restartCallback(Ref *pSender)
|
2014-01-03 01:14:12 +08:00
|
|
|
{
|
|
|
|
Scene *s = new SceneEditorTestScene();
|
|
|
|
s->addChild(Restart());
|
|
|
|
Director::getInstance()->replaceScene(s);
|
|
|
|
s->release();
|
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void SceneEditorTestLayer::nextCallback(Ref *pSender)
|
2014-01-03 01:14:12 +08:00
|
|
|
{
|
|
|
|
Scene *s = new SceneEditorTestScene();
|
|
|
|
s->addChild(Next());
|
|
|
|
Director::getInstance()->replaceScene(s);
|
|
|
|
s->release();
|
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void SceneEditorTestLayer::backCallback(Ref *pSender)
|
2014-01-03 01:14:12 +08:00
|
|
|
{
|
|
|
|
Scene *s = new SceneEditorTestScene();
|
|
|
|
s->addChild(Back());
|
|
|
|
Director::getInstance()->replaceScene(s);
|
|
|
|
s->release();
|
|
|
|
}
|
|
|
|
|
2014-05-31 07:42:05 +08:00
|
|
|
void SceneEditorTestLayer::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
|
2014-01-03 01:14:12 +08:00
|
|
|
{
|
2014-05-31 07:42:05 +08:00
|
|
|
Layer::draw(renderer, transform, flags);
|
2014-01-03 01:14:12 +08:00
|
|
|
}
|
|
|
|
|
2014-06-25 14:32:38 +08:00
|
|
|
void SceneEditorTestLayer::changeLoadTypeCallback(cocos2d::Ref *pSender)
|
|
|
|
{
|
2014-06-26 10:08:17 +08:00
|
|
|
_isCsbLoad = !_isCsbLoad;
|
|
|
|
_loadtypelb->setString(_loadtypeStr[(int)_isCsbLoad]);
|
|
|
|
loadFileChangeHelper(_filePath);
|
2014-06-25 14:32:38 +08:00
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
if(_rootNode != nullptr)
|
2014-06-25 14:32:38 +08:00
|
|
|
{
|
2014-06-26 10:08:17 +08:00
|
|
|
this->removeChild(_rootNode);
|
|
|
|
_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(_filePath.c_str());
|
2014-07-10 00:45:27 +08:00
|
|
|
if (_rootNode == nullptr)
|
2014-06-25 14:32:38 +08:00
|
|
|
{
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
defaultPlay();
|
2014-06-26 10:08:17 +08:00
|
|
|
this->addChild(_rootNode);
|
2014-06-25 14:32:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SceneEditorTestLayer::loadFileChangeHelper(std::string& filePathName)
|
|
|
|
{
|
|
|
|
std::string::size_type n = filePathName.find_last_of(".");
|
|
|
|
if(n == std::string::npos)
|
|
|
|
return;
|
|
|
|
filePathName = filePathName.substr(0,n);
|
2014-06-26 10:08:17 +08:00
|
|
|
if(_isCsbLoad)
|
2014-06-25 14:32:38 +08:00
|
|
|
filePathName.append(".csb");
|
|
|
|
else
|
|
|
|
filePathName.append(".json");
|
|
|
|
}
|
2014-01-03 01:14:12 +08:00
|
|
|
|
2014-01-03 20:33:07 +08:00
|
|
|
LoadSceneEdtiorFileTest::LoadSceneEdtiorFileTest()
|
2014-01-03 01:14:12 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-01-03 20:33:07 +08:00
|
|
|
LoadSceneEdtiorFileTest::~LoadSceneEdtiorFileTest()
|
2014-01-03 01:14:12 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-01-03 20:33:07 +08:00
|
|
|
std::string LoadSceneEdtiorFileTest::title()
|
2014-01-03 01:14:12 +08:00
|
|
|
{
|
|
|
|
return "loadSceneEdtiorFile Test";
|
|
|
|
}
|
|
|
|
|
2014-01-03 20:33:07 +08:00
|
|
|
void LoadSceneEdtiorFileTest::onEnter()
|
2014-01-03 01:14:12 +08:00
|
|
|
{
|
|
|
|
SceneEditorTestLayer::onEnter();
|
|
|
|
do
|
|
|
|
{
|
|
|
|
Node *root = createGameScene();
|
|
|
|
CC_BREAK_IF(!root);
|
|
|
|
this->addChild(root, 0, 1);
|
|
|
|
} while (0);
|
|
|
|
}
|
|
|
|
|
2014-01-03 20:33:07 +08:00
|
|
|
void LoadSceneEdtiorFileTest::onExit()
|
2014-01-03 01:14:12 +08:00
|
|
|
{
|
2014-01-04 14:23:40 +08:00
|
|
|
ArmatureDataManager::destroyInstance();
|
|
|
|
SceneReader::destroyInstance();
|
|
|
|
ActionManagerEx::destroyInstance();
|
|
|
|
GUIReader::destroyInstance();
|
2014-01-03 01:14:12 +08:00
|
|
|
SceneEditorTestLayer::onExit();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-03 20:33:07 +08:00
|
|
|
cocos2d::Node* LoadSceneEdtiorFileTest::createGameScene()
|
2014-01-03 01:14:12 +08:00
|
|
|
{
|
2014-06-26 10:08:17 +08:00
|
|
|
_filePath = "scenetest/LoadSceneEdtiorFileTest/FishJoy2.json"; //default is json
|
|
|
|
_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(_filePath.c_str());
|
2014-07-10 00:45:27 +08:00
|
|
|
if (_rootNode == nullptr)
|
2014-01-03 01:14:12 +08:00
|
|
|
{
|
2014-07-10 00:45:27 +08:00
|
|
|
return nullptr;
|
2014-01-03 01:14:12 +08:00
|
|
|
}
|
2014-06-25 14:32:38 +08:00
|
|
|
defaultPlay();
|
2014-06-26 10:08:17 +08:00
|
|
|
return _rootNode;
|
2014-06-25 14:32:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void LoadSceneEdtiorFileTest::defaultPlay()
|
|
|
|
{
|
|
|
|
|
2014-01-03 01:14:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
SpriteComponentTest::SpriteComponentTest()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SpriteComponentTest::~SpriteComponentTest()
|
|
|
|
{
|
|
|
|
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
2014-01-03 01:14:12 +08:00
|
|
|
std::string SpriteComponentTest::title()
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
2014-01-03 01:14:12 +08:00
|
|
|
return "Sprite Component Test";
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
2014-01-03 01:14:12 +08:00
|
|
|
void SpriteComponentTest::onEnter()
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
2014-01-03 01:14:12 +08:00
|
|
|
SceneEditorTestLayer::onEnter();
|
2013-09-20 22:23:13 +08:00
|
|
|
do
|
|
|
|
{
|
2014-01-03 01:14:12 +08:00
|
|
|
Node *root = createGameScene();
|
|
|
|
CC_BREAK_IF(!root);
|
|
|
|
this->addChild(root, 0, 1);
|
|
|
|
} while (0);
|
|
|
|
}
|
2013-09-20 22:23:13 +08:00
|
|
|
|
2014-01-03 01:14:12 +08:00
|
|
|
void SpriteComponentTest::onExit()
|
|
|
|
{
|
2014-01-04 14:23:40 +08:00
|
|
|
ArmatureDataManager::destroyInstance();
|
|
|
|
SceneReader::destroyInstance();
|
|
|
|
ActionManagerEx::destroyInstance();
|
|
|
|
GUIReader::destroyInstance();
|
2014-01-03 01:14:12 +08:00
|
|
|
SceneEditorTestLayer::onExit();
|
|
|
|
}
|
2013-09-20 22:23:13 +08:00
|
|
|
|
2014-01-03 01:14:12 +08:00
|
|
|
cocos2d::Node* SpriteComponentTest::createGameScene()
|
|
|
|
{
|
2014-06-26 10:08:17 +08:00
|
|
|
_filePath = "scenetest/SpriteComponentTest/SpriteComponentTest.json";
|
|
|
|
_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(_filePath.c_str());
|
2014-07-10 00:45:27 +08:00
|
|
|
if (_rootNode == nullptr)
|
2014-01-03 01:14:12 +08:00
|
|
|
{
|
2014-07-10 00:45:27 +08:00
|
|
|
return nullptr;
|
2014-01-03 01:14:12 +08:00
|
|
|
}
|
|
|
|
|
2014-06-25 14:32:38 +08:00
|
|
|
defaultPlay();
|
|
|
|
|
2014-06-26 10:08:17 +08:00
|
|
|
return _rootNode;
|
2014-06-25 14:32:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SpriteComponentTest::defaultPlay()
|
|
|
|
{
|
2014-01-03 01:14:12 +08:00
|
|
|
ActionInterval* action1 = CCBlink::create(2, 10);
|
|
|
|
ActionInterval* action2 = CCBlink::create(2, 5);
|
|
|
|
|
2014-06-26 10:08:17 +08:00
|
|
|
ComRender *pSister1 = static_cast<ComRender*>(_rootNode->getChildByTag(10003)->getComponent("CCSprite"));
|
2014-01-03 19:30:47 +08:00
|
|
|
pSister1->getNode()->runAction(action1);
|
2014-01-03 01:14:12 +08:00
|
|
|
|
2014-06-26 10:08:17 +08:00
|
|
|
ComRender *pSister2 = static_cast<ComRender*>(_rootNode->getChildByTag(10004)->getComponent("CCSprite"));
|
2014-01-03 19:30:47 +08:00
|
|
|
pSister2->getNode()->runAction(action2);
|
2014-01-03 01:14:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ArmatureComponentTest::ArmatureComponentTest()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ArmatureComponentTest::~ArmatureComponentTest()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ArmatureComponentTest::title()
|
|
|
|
{
|
|
|
|
return "Armature Component Test";
|
|
|
|
}
|
|
|
|
|
|
|
|
void ArmatureComponentTest::onEnter()
|
|
|
|
{
|
|
|
|
SceneEditorTestLayer::onEnter();
|
|
|
|
do
|
|
|
|
{
|
|
|
|
Node *root = createGameScene();
|
|
|
|
CC_BREAK_IF(!root);
|
|
|
|
this->addChild(root, 0, 1);
|
2013-09-20 22:23:13 +08:00
|
|
|
} while (0);
|
2014-01-03 01:14:12 +08:00
|
|
|
}
|
2013-09-20 22:23:13 +08:00
|
|
|
|
2014-01-03 01:14:12 +08:00
|
|
|
void ArmatureComponentTest::onExit()
|
|
|
|
{
|
2014-01-04 14:23:40 +08:00
|
|
|
ArmatureDataManager::destroyInstance();
|
|
|
|
SceneReader::destroyInstance();
|
|
|
|
ActionManagerEx::destroyInstance();
|
|
|
|
GUIReader::destroyInstance();
|
2014-01-03 01:14:12 +08:00
|
|
|
SceneEditorTestLayer::onExit();
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
2014-01-03 01:14:12 +08:00
|
|
|
cocos2d::Node* ArmatureComponentTest::createGameScene()
|
|
|
|
{
|
2014-06-26 10:08:17 +08:00
|
|
|
_filePath = "scenetest/ArmatureComponentTest/ArmatureComponentTest.json";
|
|
|
|
_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(_filePath.c_str());
|
2014-07-10 00:45:27 +08:00
|
|
|
if (_rootNode == nullptr)
|
2014-01-03 01:14:12 +08:00
|
|
|
{
|
2014-07-10 00:45:27 +08:00
|
|
|
return nullptr;
|
2014-01-03 01:14:12 +08:00
|
|
|
}
|
2014-06-25 14:32:38 +08:00
|
|
|
defaultPlay();
|
2014-06-26 10:08:17 +08:00
|
|
|
return _rootNode;
|
2014-06-25 14:32:38 +08:00
|
|
|
}
|
2014-01-03 01:14:12 +08:00
|
|
|
|
2014-06-25 14:32:38 +08:00
|
|
|
void ArmatureComponentTest::defaultPlay()
|
|
|
|
{
|
2014-06-26 10:08:17 +08:00
|
|
|
ComRender *pBlowFish = static_cast<ComRender*>(_rootNode->getChildByTag(10007)->getComponent("CCArmature"));
|
2014-06-25 14:32:38 +08:00
|
|
|
pBlowFish->getNode()->runAction(MoveBy::create(10.0f, Point(-1000.0f, 0)));
|
|
|
|
|
2014-06-26 10:08:17 +08:00
|
|
|
ComRender *pButterflyfish = static_cast<ComRender*>(_rootNode->getChildByTag(10008)->getComponent("CCArmature"));
|
2014-06-25 14:32:38 +08:00
|
|
|
pButterflyfish->getNode()->runAction(MoveBy::create(10.0f, Point(-1000.0f, 0)));
|
2014-01-03 01:14:12 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UIComponentTest::UIComponentTest()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
UIComponentTest::~UIComponentTest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string UIComponentTest::title()
|
|
|
|
{
|
|
|
|
return "UI Component Test";
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIComponentTest::onEnter()
|
|
|
|
{
|
|
|
|
SceneEditorTestLayer::onEnter();
|
|
|
|
do
|
|
|
|
{
|
|
|
|
Node *root = createGameScene();
|
|
|
|
CC_BREAK_IF(!root);
|
|
|
|
this->addChild(root, 0, 1);
|
|
|
|
} while (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void UIComponentTest::onExit()
|
|
|
|
{
|
2014-01-04 14:23:40 +08:00
|
|
|
ArmatureDataManager::destroyInstance();
|
|
|
|
SceneReader::destroyInstance();
|
|
|
|
ActionManagerEx::destroyInstance();
|
|
|
|
GUIReader::destroyInstance();
|
2014-01-03 01:14:12 +08:00
|
|
|
SceneEditorTestLayer::onExit();
|
|
|
|
}
|
|
|
|
|
|
|
|
cocos2d::Node* UIComponentTest::createGameScene()
|
|
|
|
{
|
2014-06-26 10:08:17 +08:00
|
|
|
_filePath = "scenetest/UIComponentTest/UIComponentTest.json";
|
|
|
|
_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(_filePath.c_str());
|
2014-07-10 00:45:27 +08:00
|
|
|
if (_rootNode == nullptr)
|
2014-01-03 01:14:12 +08:00
|
|
|
{
|
2014-07-10 00:45:27 +08:00
|
|
|
return nullptr;
|
2014-01-03 01:14:12 +08:00
|
|
|
}
|
2014-06-25 14:32:38 +08:00
|
|
|
defaultPlay();
|
|
|
|
|
2014-06-26 10:08:17 +08:00
|
|
|
return _rootNode;
|
2014-01-03 01:14:12 +08:00
|
|
|
}
|
|
|
|
|
2014-05-09 14:30:39 +08:00
|
|
|
void UIComponentTest::touchEvent(Ref *pSender, ui::Widget::TouchEventType type)
|
2014-01-03 01:14:12 +08:00
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
2014-05-09 14:30:39 +08:00
|
|
|
case ui::Widget::TouchEventType::BEGAN:
|
2014-01-03 01:14:12 +08:00
|
|
|
{
|
2014-06-26 10:08:17 +08:00
|
|
|
ComRender *pBlowFish = static_cast<ComRender*>(_rootNode->getChildByTag(10010)->getComponent("CCArmature"));
|
2014-05-15 01:07:09 +08:00
|
|
|
pBlowFish->getNode()->runAction(CCMoveBy::create(10.0f, Vec2(-1000.0f, 0)));
|
2014-01-03 01:14:12 +08:00
|
|
|
|
2014-06-26 10:08:17 +08:00
|
|
|
ComRender *pButterflyfish = static_cast<ComRender*>(_rootNode->getChildByTag(10011)->getComponent("CCArmature"));
|
2014-05-15 01:07:09 +08:00
|
|
|
pButterflyfish->getNode()->runAction(CCMoveBy::create(10.0f, Vec2(-1000.0f, 0)));
|
2014-01-03 01:14:12 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-25 14:32:38 +08:00
|
|
|
void UIComponentTest::defaultPlay()
|
|
|
|
{
|
|
|
|
|
2014-06-26 10:08:17 +08:00
|
|
|
ComRender *render = static_cast<ComRender*>(_rootNode->getChildByTag(10025)->getComponent("GUIComponent"));
|
2014-06-25 14:32:38 +08:00
|
|
|
Widget* widget = static_cast<cocos2d::ui::Widget*>(render->getNode());
|
|
|
|
Button* button = static_cast<Button*>(widget->getChildByName("Button_156"));
|
|
|
|
button->addTouchEventListener(CC_CALLBACK_2(UIComponentTest::touchEvent, this));
|
|
|
|
}
|
|
|
|
|
2014-01-03 01:14:12 +08:00
|
|
|
TmxMapComponentTest::TmxMapComponentTest()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
TmxMapComponentTest::~TmxMapComponentTest()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string TmxMapComponentTest::title()
|
|
|
|
{
|
|
|
|
return "TmxMap Component Test";
|
|
|
|
}
|
|
|
|
|
|
|
|
void TmxMapComponentTest::onEnter()
|
|
|
|
{
|
|
|
|
SceneEditorTestLayer::onEnter();
|
|
|
|
do
|
|
|
|
{
|
|
|
|
Node *root = createGameScene();
|
|
|
|
CC_BREAK_IF(!root);
|
|
|
|
this->addChild(root, 0, 1);
|
|
|
|
} while (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TmxMapComponentTest::onExit()
|
|
|
|
{
|
2014-01-04 14:23:40 +08:00
|
|
|
ArmatureDataManager::destroyInstance();
|
|
|
|
SceneReader::destroyInstance();
|
|
|
|
ActionManagerEx::destroyInstance();
|
|
|
|
GUIReader::destroyInstance();
|
2014-01-03 01:14:12 +08:00
|
|
|
SceneEditorTestLayer::onExit();
|
|
|
|
}
|
|
|
|
|
|
|
|
cocos2d::Node* TmxMapComponentTest::createGameScene()
|
|
|
|
{
|
2014-06-26 10:08:17 +08:00
|
|
|
_filePath = "scenetest/TmxMapComponentTest/TmxMapComponentTest.json";
|
|
|
|
_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(_filePath.c_str());
|
2014-07-10 00:45:27 +08:00
|
|
|
if (_rootNode == nullptr)
|
2014-01-03 01:14:12 +08:00
|
|
|
{
|
2014-07-10 00:45:27 +08:00
|
|
|
return nullptr;
|
2014-01-03 01:14:12 +08:00
|
|
|
}
|
2014-06-25 14:32:38 +08:00
|
|
|
defaultPlay();
|
2014-06-26 10:08:17 +08:00
|
|
|
return _rootNode;
|
2014-06-25 14:32:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TmxMapComponentTest::defaultPlay()
|
|
|
|
{
|
2014-06-26 10:08:17 +08:00
|
|
|
ComRender *tmxMap = static_cast<ComRender*>(_rootNode->getChildByTag(10015)->getComponent("CCTMXTiledMap"));
|
2014-06-25 14:32:38 +08:00
|
|
|
ActionInterval *actionTo = CCSkewTo::create(2, 0.f, 2.f);
|
|
|
|
ActionInterval *rotateTo = CCRotateTo::create(2, 61.0f);
|
|
|
|
ActionInterval *actionScaleTo = CCScaleTo::create(2, -0.44f, 0.47f);
|
2014-01-03 01:14:12 +08:00
|
|
|
|
2014-06-25 14:32:38 +08:00
|
|
|
ActionInterval *actionScaleToBack = CCScaleTo::create(2, 1.0f, 1.0f);
|
|
|
|
ActionInterval *rotateToBack = CCRotateTo::create(2, 0);
|
|
|
|
ActionInterval *actionToBack = CCSkewTo::create(2, 0, 0);
|
2014-01-03 01:14:12 +08:00
|
|
|
|
2014-07-10 00:45:27 +08:00
|
|
|
tmxMap->getNode()->runAction(CCSequence::create(actionTo, actionToBack, nullptr));
|
|
|
|
tmxMap->getNode()->runAction(CCSequence::create(rotateTo, rotateToBack, nullptr));
|
|
|
|
tmxMap->getNode()->runAction(CCSequence::create(actionScaleTo, actionScaleToBack, nullptr));
|
2014-01-03 01:14:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ParticleComponentTest::ParticleComponentTest()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ParticleComponentTest::~ParticleComponentTest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string ParticleComponentTest::title()
|
|
|
|
{
|
|
|
|
return "Particle Component Test";
|
|
|
|
}
|
|
|
|
|
|
|
|
void ParticleComponentTest::onEnter()
|
|
|
|
{
|
|
|
|
SceneEditorTestLayer::onEnter();
|
|
|
|
do
|
|
|
|
{
|
|
|
|
Node *root = createGameScene();
|
|
|
|
CC_BREAK_IF(!root);
|
|
|
|
this->addChild(root, 0, 1);
|
|
|
|
} while (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ParticleComponentTest::onExit()
|
|
|
|
{
|
2014-01-04 14:23:40 +08:00
|
|
|
ArmatureDataManager::destroyInstance();
|
|
|
|
SceneReader::destroyInstance();
|
|
|
|
ActionManagerEx::destroyInstance();
|
|
|
|
GUIReader::destroyInstance();
|
2014-01-03 01:14:12 +08:00
|
|
|
SceneEditorTestLayer::onExit();
|
|
|
|
}
|
|
|
|
|
|
|
|
cocos2d::Node* ParticleComponentTest::createGameScene()
|
|
|
|
{
|
2014-06-26 10:08:17 +08:00
|
|
|
_filePath = "scenetest/ParticleComponentTest/ParticleComponentTest.json";
|
|
|
|
_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(_filePath.c_str());
|
2014-07-10 00:45:27 +08:00
|
|
|
if (_rootNode == nullptr)
|
2014-01-03 01:14:12 +08:00
|
|
|
{
|
2014-07-10 00:45:27 +08:00
|
|
|
return nullptr;
|
2014-01-03 01:14:12 +08:00
|
|
|
}
|
2014-06-25 14:32:38 +08:00
|
|
|
defaultPlay();
|
2014-06-26 10:08:17 +08:00
|
|
|
return _rootNode;
|
2014-06-25 14:32:38 +08:00
|
|
|
}
|
2014-01-03 01:14:12 +08:00
|
|
|
|
2014-06-25 14:32:38 +08:00
|
|
|
void ParticleComponentTest::defaultPlay()
|
|
|
|
{
|
2014-06-26 10:08:17 +08:00
|
|
|
ComRender* Particle = static_cast<ComRender*>(_rootNode->getChildByTag(10020)->getComponent("CCParticleSystemQuad"));
|
2014-06-25 14:32:38 +08:00
|
|
|
ActionInterval* jump = CCJumpBy::create(5, Point(-500,0), 50, 4);
|
2014-07-10 00:45:27 +08:00
|
|
|
FiniteTimeAction* action = CCSequence::create( jump, jump->reverse(), nullptr);
|
2014-01-03 19:30:47 +08:00
|
|
|
Particle->getNode()->runAction(action);
|
2014-01-03 01:14:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EffectComponentTest::EffectComponentTest()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
EffectComponentTest::~EffectComponentTest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string EffectComponentTest::title()
|
|
|
|
{
|
|
|
|
return "Effect Component Test";
|
|
|
|
}
|
|
|
|
|
|
|
|
void EffectComponentTest::onEnter()
|
|
|
|
{
|
|
|
|
SceneEditorTestLayer::onEnter();
|
|
|
|
do
|
|
|
|
{
|
|
|
|
Node *root = createGameScene();
|
|
|
|
CC_BREAK_IF(!root);
|
|
|
|
this->addChild(root, 0, 1);
|
|
|
|
} while (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EffectComponentTest::onExit()
|
|
|
|
{
|
2014-01-04 14:23:40 +08:00
|
|
|
ArmatureDataManager::destroyInstance();
|
|
|
|
SceneReader::destroyInstance();
|
|
|
|
ActionManagerEx::destroyInstance();
|
|
|
|
GUIReader::destroyInstance();
|
2014-01-03 01:14:12 +08:00
|
|
|
SceneEditorTestLayer::onExit();
|
|
|
|
}
|
|
|
|
|
|
|
|
cocos2d::Node* EffectComponentTest::createGameScene()
|
|
|
|
{
|
2014-06-26 10:08:17 +08:00
|
|
|
_filePath = "scenetest/EffectComponentTest/EffectComponentTest.json";
|
|
|
|
_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(_filePath.c_str());
|
2014-07-10 00:45:27 +08:00
|
|
|
if (_rootNode == nullptr)
|
2014-01-03 01:14:12 +08:00
|
|
|
{
|
2014-07-10 00:45:27 +08:00
|
|
|
return nullptr;
|
2014-01-03 01:14:12 +08:00
|
|
|
}
|
2014-06-25 14:32:38 +08:00
|
|
|
defaultPlay();
|
2014-06-26 10:08:17 +08:00
|
|
|
return _rootNode;
|
2014-01-03 01:14:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void EffectComponentTest::animationEvent(Armature *armature, MovementEventType movementType, const std::string& movementID)
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
2014-01-03 01:14:12 +08:00
|
|
|
std::string id = movementID;
|
|
|
|
|
|
|
|
if (movementType == LOOP_COMPLETE)
|
|
|
|
{
|
|
|
|
if (id.compare("Fire") == 0)
|
|
|
|
{
|
2014-06-26 10:08:17 +08:00
|
|
|
ComAudio *pAudio = static_cast<ComAudio*>(_rootNode->getChildByTag(10015)->getComponent("CCComAudio"));
|
2014-01-03 01:14:12 +08:00
|
|
|
pAudio->playEffect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-25 14:32:38 +08:00
|
|
|
void EffectComponentTest::defaultPlay()
|
|
|
|
{
|
2014-06-26 10:08:17 +08:00
|
|
|
ComRender *render = static_cast<ComRender*>(_rootNode->getChildByTag(10015)->getComponent("CCArmature"));
|
2014-06-25 14:32:38 +08:00
|
|
|
Armature *pAr = static_cast<Armature*>(render->getNode());
|
|
|
|
pAr->getAnimation()->setMovementEventCallFunc(CC_CALLBACK_0(EffectComponentTest::animationEvent, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
|
|
|
|
}
|
|
|
|
|
2014-01-03 01:14:12 +08:00
|
|
|
BackgroundComponentTest::BackgroundComponentTest()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
BackgroundComponentTest::~BackgroundComponentTest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string BackgroundComponentTest::title()
|
|
|
|
{
|
|
|
|
return "Background Component Test";
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackgroundComponentTest::onEnter()
|
|
|
|
{
|
|
|
|
SceneEditorTestLayer::onEnter();
|
2013-09-20 22:23:13 +08:00
|
|
|
do
|
|
|
|
{
|
|
|
|
Node *root = createGameScene();
|
|
|
|
CC_BREAK_IF(!root);
|
|
|
|
this->addChild(root, 0, 1);
|
2014-01-03 01:14:12 +08:00
|
|
|
} while (0);
|
|
|
|
}
|
2013-09-20 22:23:13 +08:00
|
|
|
|
2014-01-03 01:14:12 +08:00
|
|
|
void BackgroundComponentTest::onExit()
|
|
|
|
{
|
2014-01-04 14:23:40 +08:00
|
|
|
ArmatureDataManager::destroyInstance();
|
|
|
|
SceneReader::destroyInstance();
|
|
|
|
ActionManagerEx::destroyInstance();
|
|
|
|
GUIReader::destroyInstance();
|
2014-01-03 01:14:12 +08:00
|
|
|
SceneEditorTestLayer::onExit();
|
|
|
|
}
|
|
|
|
|
|
|
|
cocos2d::Node* BackgroundComponentTest::createGameScene()
|
|
|
|
{
|
2014-06-26 10:08:17 +08:00
|
|
|
_filePath = "scenetest/BackgroundComponentTest/BackgroundComponentTest.json";
|
|
|
|
_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(_filePath.c_str());
|
2014-07-10 00:45:27 +08:00
|
|
|
if (_rootNode == nullptr)
|
2014-01-03 01:14:12 +08:00
|
|
|
{
|
2014-07-10 00:45:27 +08:00
|
|
|
return nullptr;
|
2014-01-03 01:14:12 +08:00
|
|
|
}
|
2014-06-25 14:32:38 +08:00
|
|
|
defaultPlay();
|
2014-06-26 10:08:17 +08:00
|
|
|
return _rootNode;
|
2014-06-25 14:32:38 +08:00
|
|
|
}
|
2014-01-03 01:14:12 +08:00
|
|
|
|
2014-06-25 14:32:38 +08:00
|
|
|
void BackgroundComponentTest::defaultPlay()
|
|
|
|
{
|
2014-06-26 10:08:17 +08:00
|
|
|
ComAudio *Audio = static_cast<ComAudio*>(_rootNode->getComponent("CCBackgroundAudio"));
|
2014-01-03 01:14:12 +08:00
|
|
|
Audio->playBackgroundMusic();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AttributeComponentTest::AttributeComponentTest()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
AttributeComponentTest::~AttributeComponentTest()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string AttributeComponentTest::title()
|
|
|
|
{
|
|
|
|
return "Attribute Component Test";
|
|
|
|
}
|
|
|
|
|
|
|
|
void AttributeComponentTest::onEnter()
|
|
|
|
{
|
|
|
|
SceneEditorTestLayer::onEnter();
|
|
|
|
do
|
|
|
|
{
|
|
|
|
Node *root = createGameScene();
|
|
|
|
CC_BREAK_IF(!root);
|
2014-06-25 14:32:38 +08:00
|
|
|
defaultPlay();
|
2014-01-03 01:14:12 +08:00
|
|
|
this->addChild(root, 0, 1);
|
2013-09-20 22:23:13 +08:00
|
|
|
} while (0);
|
2014-01-03 01:14:12 +08:00
|
|
|
}
|
2013-09-20 22:23:13 +08:00
|
|
|
|
2014-01-03 01:14:12 +08:00
|
|
|
void AttributeComponentTest::onExit()
|
|
|
|
{
|
2014-01-04 14:23:40 +08:00
|
|
|
ArmatureDataManager::destroyInstance();
|
|
|
|
SceneReader::destroyInstance();
|
|
|
|
ActionManagerEx::destroyInstance();
|
|
|
|
GUIReader::destroyInstance();
|
2014-01-03 01:14:12 +08:00
|
|
|
SceneEditorTestLayer::onExit();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AttributeComponentTest::initData()
|
|
|
|
{
|
|
|
|
bool bRet = false;
|
2014-01-03 01:42:14 +08:00
|
|
|
rapidjson::Document doc;
|
2014-01-03 01:14:12 +08:00
|
|
|
do {
|
2014-06-26 10:08:17 +08:00
|
|
|
CC_BREAK_IF(_rootNode == nullptr);
|
|
|
|
ComAttribute *attribute = static_cast<ComAttribute*>(_rootNode->getChildByTag(10015)->getComponent("CCComAttribute"));
|
2014-01-03 01:42:14 +08:00
|
|
|
CC_BREAK_IF(attribute == nullptr);
|
2014-01-03 19:30:47 +08:00
|
|
|
log("Name: %s, HP: %f, MP: %f", attribute->getString("name").c_str(), attribute->getFloat("maxHP"), attribute->getFloat("maxMP"));
|
2014-01-03 01:14:12 +08:00
|
|
|
|
|
|
|
bRet = true;
|
|
|
|
} while (0);
|
2013-09-20 22:23:13 +08:00
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
2014-01-03 01:14:12 +08:00
|
|
|
cocos2d::Node* AttributeComponentTest::createGameScene()
|
|
|
|
{
|
2014-06-26 10:08:17 +08:00
|
|
|
_filePath = "scenetest/AttributeComponentTest/AttributeComponentTest.json";
|
|
|
|
_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(_filePath.c_str());
|
2014-07-10 00:45:27 +08:00
|
|
|
if (_rootNode == nullptr)
|
2014-01-03 01:14:12 +08:00
|
|
|
{
|
2014-07-10 00:45:27 +08:00
|
|
|
return nullptr;
|
2014-01-03 01:14:12 +08:00
|
|
|
}
|
2014-06-26 10:08:17 +08:00
|
|
|
return _rootNode;
|
2014-06-25 14:32:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void AttributeComponentTest::defaultPlay()
|
|
|
|
{
|
|
|
|
initData();
|
2014-01-03 01:14:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TriggerTest::TriggerTest()
|
|
|
|
: _node(nullptr)
|
|
|
|
, _touchListener(nullptr)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
TriggerTest::~TriggerTest()
|
2013-12-26 01:17:04 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-01-03 01:14:12 +08:00
|
|
|
std::string TriggerTest::title()
|
|
|
|
{
|
|
|
|
return "Trigger Test";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// on "init" you need to initialize your instance
|
2014-01-03 01:42:14 +08:00
|
|
|
void TriggerTest::onEnter()
|
2014-01-03 01:14:12 +08:00
|
|
|
{
|
|
|
|
SceneEditorTestLayer::onEnter();
|
|
|
|
Node *root = createGameScene();
|
|
|
|
this->addChild(root, 0, 1);
|
2014-01-03 01:42:14 +08:00
|
|
|
this->schedule(schedule_selector(TriggerTest::gameLogic));
|
2014-01-03 01:14:12 +08:00
|
|
|
auto dispatcher = Director::getInstance()->getEventDispatcher();
|
|
|
|
auto listener = EventListenerTouchOneByOne::create();
|
|
|
|
listener->setSwallowTouches(true);
|
|
|
|
listener->onTouchBegan = CC_CALLBACK_2(SceneEditorTestLayer::onTouchBegan, this);
|
|
|
|
listener->onTouchMoved = CC_CALLBACK_2(SceneEditorTestLayer::onTouchMoved, this);
|
|
|
|
listener->onTouchEnded = CC_CALLBACK_2(SceneEditorTestLayer::onTouchEnded, this);
|
|
|
|
listener->onTouchCancelled = CC_CALLBACK_2(SceneEditorTestLayer::onTouchCancelled, this);
|
|
|
|
dispatcher->addEventListenerWithFixedPriority(listener, 1);
|
|
|
|
_touchListener = listener;
|
|
|
|
sendEvent(TRIGGEREVENT_ENTERSCENE);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-03 01:42:14 +08:00
|
|
|
void TriggerTest::onExit()
|
2013-12-26 01:17:04 +08:00
|
|
|
{
|
|
|
|
sendEvent(TRIGGEREVENT_LEAVESCENE);
|
2014-01-03 01:14:12 +08:00
|
|
|
this->unschedule(schedule_selector(TriggerTest::gameLogic));
|
|
|
|
auto dispatcher = Director::getInstance()->getEventDispatcher();
|
|
|
|
dispatcher->removeEventListener(_touchListener);
|
|
|
|
Device::setAccelerometerEnabled(false);
|
2014-01-04 14:23:40 +08:00
|
|
|
ArmatureDataManager::destroyInstance();
|
|
|
|
SceneReader::destroyInstance();
|
|
|
|
ActionManagerEx::destroyInstance();
|
|
|
|
GUIReader::destroyInstance();
|
2014-01-03 01:14:12 +08:00
|
|
|
SceneEditorTestLayer::onExit();
|
2013-12-26 01:17:04 +08:00
|
|
|
}
|
|
|
|
|
2014-01-03 01:42:14 +08:00
|
|
|
bool TriggerTest::onTouchBegan(Touch *touch, Event *unused_event)
|
2013-12-26 01:17:04 +08:00
|
|
|
{
|
|
|
|
sendEvent(TRIGGEREVENT_TOUCHBEGAN);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-03 01:42:14 +08:00
|
|
|
void TriggerTest::onTouchMoved(Touch *touch, Event *unused_event)
|
2013-12-26 01:17:04 +08:00
|
|
|
{
|
|
|
|
sendEvent(TRIGGEREVENT_TOUCHMOVED);
|
|
|
|
}
|
|
|
|
|
2014-01-03 01:42:14 +08:00
|
|
|
void TriggerTest::onTouchEnded(Touch *touch, Event *unused_event)
|
2013-12-26 01:17:04 +08:00
|
|
|
{
|
|
|
|
sendEvent(TRIGGEREVENT_TOUCHENDED);
|
|
|
|
}
|
|
|
|
|
2014-01-03 01:42:14 +08:00
|
|
|
void TriggerTest::onTouchCancelled(Touch *touch, Event *unused_event)
|
2013-12-26 01:17:04 +08:00
|
|
|
{
|
|
|
|
sendEvent(TRIGGEREVENT_TOUCHCANCELLED);
|
|
|
|
}
|
|
|
|
|
2014-01-03 01:42:14 +08:00
|
|
|
void TriggerTest::gameLogic(float dt)
|
2013-12-26 01:17:04 +08:00
|
|
|
{
|
|
|
|
sendEvent(TRIGGEREVENT_UPDATESCENE);
|
|
|
|
}
|
|
|
|
|
2013-11-19 00:57:22 +08:00
|
|
|
|
2014-01-03 01:42:14 +08:00
|
|
|
cocos2d::Node* TriggerTest::createGameScene()
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
2014-06-26 10:08:17 +08:00
|
|
|
_filePath = "scenetest/TriggerTest/TriggerTest.json";
|
|
|
|
_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(_filePath.c_str());
|
2014-07-10 00:45:27 +08:00
|
|
|
if (_rootNode == nullptr)
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
2014-07-10 00:45:27 +08:00
|
|
|
return nullptr;
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
2014-06-25 14:32:38 +08:00
|
|
|
|
|
|
|
defaultPlay();
|
2014-06-26 10:08:17 +08:00
|
|
|
return _rootNode;
|
2014-06-25 14:32:38 +08:00
|
|
|
}
|
|
|
|
void TriggerTest::defaultPlay()
|
|
|
|
{
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|