1.  add SceneReader Tests.
                  2.  Modify class member name.
This commit is contained in:
chengstory 2014-01-03 01:14:12 +08:00
parent 0fe73f3a5d
commit 6892d8cf6a
10 changed files with 1159 additions and 306 deletions

View File

@ -29,7 +29,7 @@ namespace cocostudio {
ComAttribute::ComAttribute(void)
{
_name = "ComAttribute";
_name = "CCComAttribute";
}
ComAttribute::~ComAttribute(void)

View File

@ -24,6 +24,7 @@
#include "cocostudio/CocoStudio.h"
#include "gui/CocosGUI.h"
#include "SimpleAudioEngine.h"
using namespace cocos2d;
using namespace gui;
@ -33,9 +34,9 @@ namespace cocostudio {
SceneReader* SceneReader::s_sharedReader = nullptr;
SceneReader::SceneReader()
: _pListener(NULL)
, _pfnSelector(NULL)
, _pNode(NULL)
: _listener(NULL)
, _fnSelector(NULL)
, _node(NULL)
{
}
@ -48,24 +49,23 @@ namespace cocostudio {
return "1.0.0.0";
}
cocos2d::Node* SceneReader::createNodeWithSceneFile(const char* pszFileName)
cocos2d::Node* SceneReader::createNodeWithSceneFile(const std::string &fileName)
{
rapidjson::Document jsonDict;
do {
CC_BREAK_IF(!readJson(pszFileName, jsonDict));
_pNode = createObject(jsonDict, NULL);
CC_BREAK_IF(!readJson(fileName, jsonDict));
_node = createObject(jsonDict, NULL);
TriggerMng::getInstance()->parse(jsonDict);
} while (0);
return _pNode;
return _node;
}
bool SceneReader::readJson(const char *pszFileName, rapidjson::Document &doc)
bool SceneReader::readJson(const std::string &fileName, rapidjson::Document &doc)
{
bool bRet = false;
do {
CC_BREAK_IF(pszFileName == NULL);
std::string jsonpath = CCFileUtils::getInstance()->fullPathForFilename(pszFileName);
std::string jsonpath = FileUtils::getInstance()->fullPathForFilename(fileName);
std::string contentStr = FileUtils::getInstance()->getStringFromFile(jsonpath);
doc.Parse<0>(contentStr.c_str());
CC_BREAK_IF(doc.HasParseError());
@ -74,26 +74,26 @@ namespace cocostudio {
return bRet;
}
Node* SceneReader::nodeByTag(Node *pParent, int nTag)
Node* SceneReader::nodeByTag(Node *parent, int tag)
{
if (pParent == NULL)
if (parent == NULL)
{
return NULL;
}
Node *_retNode = NULL;
Vector<Node*>& Children = pParent->getChildren();
Vector<Node*>& Children = parent->getChildren();
Vector<Node*>::iterator iter = Children.begin();
while (iter != Children.end())
{
Node* pNode = *iter;
if(pNode != NULL && pNode->getTag() == nTag)
if(pNode != NULL && pNode->getTag() == tag)
{
_retNode = pNode;
break;
}
else
{
_retNode = nodeByTag(pNode, nTag);
_retNode = nodeByTag(pNode, tag);
if (_retNode != NULL)
{
break;
@ -200,9 +200,9 @@ namespace cocostudio {
}
gb->addComponent(pRender);
if (_pListener && _pfnSelector)
if (_listener && _fnSelector)
{
(_pListener->*_pfnSelector)(pSprite, (void*)(&subDict));
(_listener->*_fnSelector)(pSprite, (void*)(&subDict));
}
}
else if(comName != nullptr && strcmp(comName, "CCTMXTiledMap") == 0)
@ -227,9 +227,9 @@ namespace cocostudio {
pRender->setName(pComName);
}
gb->addComponent(pRender);
if (_pListener && _pfnSelector)
if (_listener && _fnSelector)
{
(_pListener->*_pfnSelector)(pTmx, (void*)(&subDict));
(_listener->*_fnSelector)(pTmx, (void*)(&subDict));
}
}
else if(comName != nullptr && strcmp(comName, "CCParticleSystemQuad") == 0)
@ -257,9 +257,9 @@ namespace cocostudio {
pRender->setName(pComName);
}
gb->addComponent(pRender);
if (_pListener && _pfnSelector)
if (_listener && _fnSelector)
{
(_pListener->*_pfnSelector)(pParticle, (void*)(&subDict));
(_listener->*_fnSelector)(pParticle, (void*)(&subDict));
}
}
else if(comName != nullptr && strcmp(comName, "CCArmature") == 0)
@ -301,9 +301,9 @@ namespace cocostudio {
{
pAr->getAnimation()->play(actionName);
}
if (_pListener && _pfnSelector)
if (_listener && _fnSelector)
{
(_pListener->*_pfnSelector)(pAr, (void*)(&subDict));
(_listener->*_fnSelector)(pAr, (void*)(&subDict));
}
}
else if(comName != nullptr && strcmp(comName, "CCComAudio") == 0)
@ -318,10 +318,14 @@ namespace cocostudio {
continue;
}
pAudio->preloadEffect(pPath.c_str());
gb->addComponent(pAudio);
if (_pListener && _pfnSelector)
if (pComName != NULL)
{
(_pListener->*_pfnSelector)(pAudio, (void*)(&subDict));
pAudio->setName(pComName);
}
gb->addComponent(pAudio);
if (_listener && _fnSelector)
{
(_listener->*_fnSelector)(pAudio, (void*)(&subDict));
}
}
else if(comName != nullptr && strcmp(comName, "CCComAttribute") == 0)
@ -337,9 +341,9 @@ namespace cocostudio {
continue;
}
gb->addComponent(pAttribute);
if (_pListener && _pfnSelector)
if (_listener && _fnSelector)
{
(_pListener->*_pfnSelector)(pAttribute, (void*)(&subDict));
(_listener->*_fnSelector)(pAttribute, (void*)(&subDict));
}
}
else if (comName != nullptr && strcmp(comName, "CCBackgroundAudio") == 0)
@ -358,6 +362,10 @@ namespace cocostudio {
const bool bLoop = (DICTOOL->getIntValue_json(subDict, "loop") != 0);
pAudio->setLoop(bLoop);
gb->addComponent(pAudio);
if (pComName != NULL)
{
pAudio->setName(pComName);
}
pAudio->playBackgroundMusic(pPath.c_str(), bLoop);
}
else if(comName != nullptr && strcmp(comName, "GUIComponent") == 0)
@ -369,9 +377,9 @@ namespace cocostudio {
pRender->setName(pComName);
}
gb->addComponent(pRender);
if (_pListener && _pfnSelector)
if (_listener && _fnSelector)
{
(_pListener->*_pfnSelector)(widget, (void*)(&subDict));
(_listener->*_fnSelector)(widget, (void*)(&subDict));
}
}
}
@ -395,21 +403,21 @@ namespace cocostudio {
void SceneReader::setTarget(Object *rec, SEL_CallFuncOD selector)
{
_pListener = rec;
_pfnSelector = selector;
_listener = rec;
_fnSelector = selector;
}
Node* SceneReader::getNodeByTag(int nTag)
{
if (_pNode == NULL)
if (_node == NULL)
{
return NULL;
}
if (_pNode->getTag() == nTag)
if (_node->getTag() == nTag)
{
return _pNode;
return _node;
}
return nodeByTag(_pNode, nTag);
return nodeByTag(_node, nTag);
}
void SceneReader::setPropertyFromJsonDict(const rapidjson::Value &root, cocos2d::Node *node)
@ -449,6 +457,9 @@ namespace cocostudio {
{
DictionaryHelper::destroyInstance();
TriggerMng::destroyInstance();
_fnSelector = nullptr;
_listener = nullptr;
CocosDenshion::SimpleAudioEngine::end();
CC_SAFE_DELETE(s_sharedReader);
}

View File

@ -53,21 +53,21 @@ public:
* @js purge
* @lua destroySceneReader
*/
static void destroyInstance();
void destroyInstance();
static const char* sceneReaderVersion();
cocos2d::Node* createNodeWithSceneFile(const char *pszFileName);
cocos2d::Node* createNodeWithSceneFile(const std::string &fileName);
void setTarget(cocos2d::Object *rec, SEL_CallFuncOD selector);
cocos2d::Node* getNodeByTag(int nTag);
private:
cocos2d::Node* createObject(const rapidjson::Value& dict, cocos2d::Node* parent);
void setPropertyFromJsonDict(const rapidjson::Value& dict, cocos2d::Node *node);
bool readJson(const char *pszFileName, rapidjson::Document &doc);
cocos2d::Node* nodeByTag(cocos2d::Node *pParent, int nTag);
bool readJson(const std::string &fileName, rapidjson::Document& doc);
cocos2d::Node* nodeByTag(cocos2d::Node *parent, int tag);
private:
static SceneReader* s_sharedReader;
cocos2d::Object* _pListener;
SEL_CallFuncOD _pfnSelector;
cocos2d::Node* _pNode;
cocos2d::Object* _listener;
SEL_CallFuncOD _fnSelector;
cocos2d::Node* _node;
};

View File

@ -91,9 +91,9 @@ void SceneController::spriteMoveFinished(Node* sender)
void SceneController::increaseKillCount()
{
int nProjectilesDestroyed = ((ComAttribute*)(_owner->getComponent("ComAttribute")))->getInt("KillCount");
int nProjectilesDestroyed = ((ComAttribute*)(_owner->getComponent("CCComAttribute")))->getInt("KillCount");
ComAttribute *p = (ComAttribute*)(_owner->getComponent("ComAttribute"));
ComAttribute *p = (ComAttribute*)(_owner->getComponent("CCComAttribute"));
p->setInt("KillCount", ++nProjectilesDestroyed);
if (nProjectilesDestroyed >= 5)

View File

@ -5,84 +5,796 @@
#include "cocostudio/CocoStudio.h"
#include "gui/CocosGUI.h"
#include "TriggerCode/EventDef.h"
#include "../../testResource.h"
using namespace cocos2d;
using namespace cocostudio;
using namespace gui;
SceneEditorTestLayer::~SceneEditorTestLayer()
Layer *Next();
Layer *Back();
Layer *Restart();
static int s_nIdx = -1;
Layer *createTests(int index)
{
ArmatureDataManager::destroyInstance();
SceneReader::destroyInstance();
ActionManagerEx::destroyInstance();
auto dispatcher = Director::getInstance()->getEventDispatcher();
dispatcher->removeEventListener(_touchListener);
Layer *layer = nullptr;
switch(index)
{
case TEST_LOADSCENEEDITORFILE:
layer = new loadSceneEdtiorFileTest();
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();
layer->init();
break;
default:
break;
}
return layer;
}
SceneEditorTestLayer::SceneEditorTestLayer()
Layer *Next()
{
_curNode = nullptr;
_touchListener = nullptr;
++s_nIdx;
s_nIdx = s_nIdx % TEST_SCENEEDITOR_COUNT;
Layer *layer = createTests(s_nIdx);
layer->autorelease();
return layer;
}
Scene* SceneEditorTestLayer::scene()
Layer *Back()
{
Scene * scene = nullptr;
do
{
// 'scene' is an autorelease object
scene = Scene::create();
CC_BREAK_IF(! scene);
--s_nIdx;
if( s_nIdx < 0 )
s_nIdx += TEST_SCENEEDITOR_COUNT;
// 'layer' is an autorelease object
SceneEditorTestLayer *layer = SceneEditorTestLayer::create();
CC_BREAK_IF(! layer);
Layer *layer = createTests(s_nIdx);
layer->autorelease();
// add layer as a child to scene
scene->addChild(layer);
} while (0);
// return the scene
return scene;
return layer;
}
// on "init" you need to initialize your instance
bool SceneEditorTestLayer::init()
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);
}
void SceneEditorTestScene::MainMenuCallback(Object *pSender)
{
removeAllChildren();
}
void SceneEditorTestLayer::onEnter()
{
CCLayer::onEnter();
// add title and subtitle
std::string str = title();
const char *pTitle = str.c_str();
LabelTTF *label = LabelTTF::create(pTitle, "Arial", 18);
label->setColor(Color3B(255, 255, 255));
addChild(label, 1, 10000);
label->setPosition( Point(VisibleRect::center().x, VisibleRect::top().y - 30) );
std::string strSubtitle = subtitle();
if( ! strSubtitle.empty() )
{
LabelTTF *l = LabelTTF::create(strSubtitle.c_str(), "Arial", 18);
l->setColor(Color3B(0, 0, 0));
addChild(l, 1, 10001);
l->setPosition(Point(VisibleRect::center().x, VisibleRect::top().y - 60) );
}
// 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;
menu->setPosition(Point(0, 0));
backItem->setPosition(Point(VisibleRect::center().x - restartItem->getContentSize().width * 2 * fScale, VisibleRect::bottom().y + restartItem->getContentSize().height / 2));
backItem->setScale(fScale);
restartItem->setPosition(Point(VisibleRect::center().x, VisibleRect::bottom().y + restartItem->getContentSize().height / 2));
restartItem->setScale(fScale);
nextItem->setPosition(Point(VisibleRect::center().x + restartItem->getContentSize().width * 2 * fScale, VisibleRect::bottom().y + restartItem->getContentSize().height / 2));
nextItem->setScale(fScale);
addChild(menu, 100);
setShaderProgram(ShaderCache::getInstance()->getProgram(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR));
}
void SceneEditorTestLayer::onExit()
{
removeAllChildren();
backItem = restartItem = nextItem = nullptr;
Layer::onExit();
}
std::string SceneEditorTestLayer::title()
{
return "SceneReader Test LoadSceneEditorFile";
}
std::string SceneEditorTestLayer::subtitle()
{
return "";
}
void SceneEditorTestLayer::restartCallback(Object *pSender)
{
Scene *s = new SceneEditorTestScene();
s->addChild(Restart());
Director::getInstance()->replaceScene(s);
s->release();
}
void SceneEditorTestLayer::nextCallback(Object *pSender)
{
Scene *s = new SceneEditorTestScene();
s->addChild(Next());
Director::getInstance()->replaceScene(s);
s->release();
}
void SceneEditorTestLayer::backCallback(Object *pSender)
{
Scene *s = new SceneEditorTestScene();
s->addChild(Back());
Director::getInstance()->replaceScene(s);
s->release();
}
void SceneEditorTestLayer::draw()
{
Layer::draw();
}
loadSceneEdtiorFileTest::loadSceneEdtiorFileTest()
{
}
loadSceneEdtiorFileTest::~loadSceneEdtiorFileTest()
{
}
std::string loadSceneEdtiorFileTest::title()
{
return "loadSceneEdtiorFile Test";
}
void loadSceneEdtiorFileTest::onEnter()
{
SceneEditorTestLayer::onEnter();
bool bRet = false;
do
{
Node *root = createGameScene();
CC_BREAK_IF(!root);
this->addChild(root, 0, 1);
sendEvent(TRIGGEREVENT_INITSCENE);
this->schedule(schedule_selector(SceneEditorTestLayer::gameLogic));
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;
bRet = true;
} while (0);
}
void loadSceneEdtiorFileTest::onExit()
{
ArmatureDataManager::getInstance()->destroyInstance();
SceneReader::getInstance()->destroyInstance();
ActionManagerEx::getInstance()->destroyInstance();
GUIReader::shareReader()->purgeGUIReader();
SceneEditorTestLayer::onExit();
}
cocos2d::Node* loadSceneEdtiorFileTest::createGameScene()
{
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/loadSceneEdtiorFileTest/FishJoy2.json");
if (node == nullptr)
{
return nullptr;
}
ActionManagerEx::getInstance()->playActionByName("startMenu_1.json","Animation1");
return node;
}
SpriteComponentTest::SpriteComponentTest()
{
}
SpriteComponentTest::~SpriteComponentTest()
{
}
std::string SpriteComponentTest::title()
{
return "Sprite Component Test";
}
void SpriteComponentTest::onEnter()
{
SceneEditorTestLayer::onEnter();
bool bRet = false;
do
{
Node *root = createGameScene();
CC_BREAK_IF(!root);
this->addChild(root, 0, 1);
bRet = true;
} while (0);
}
void SpriteComponentTest::onExit()
{
ArmatureDataManager::getInstance()->destroyInstance();
SceneReader::getInstance()->destroyInstance();
ActionManagerEx::getInstance()->destroyInstance();
GUIReader::shareReader()->purgeGUIReader();
SceneEditorTestLayer::onExit();
}
cocos2d::Node* SpriteComponentTest::createGameScene()
{
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/SpriteComponentTest/SpriteComponentTest.json");
if (node == nullptr)
{
return nullptr;
}
ActionInterval* action1 = CCBlink::create(2, 10);
ActionInterval* action2 = CCBlink::create(2, 5);
Sprite *pSister1 = static_cast<Sprite*>(node->getChildByTag(10003)->getComponent("CCSprite")->getNode());
pSister1->runAction(action1);
Sprite *pSister2 = static_cast<Sprite*>(node->getChildByTag(10004)->getComponent("CCSprite")->getNode());
pSister2->runAction(action2);
return node;
}
ArmatureComponentTest::ArmatureComponentTest()
{
}
ArmatureComponentTest::~ArmatureComponentTest()
{
}
std::string ArmatureComponentTest::title()
{
return "Armature Component Test";
}
void ArmatureComponentTest::onEnter()
{
SceneEditorTestLayer::onEnter();
bool bRet = false;
do
{
Node *root = createGameScene();
CC_BREAK_IF(!root);
this->addChild(root, 0, 1);
bRet = true;
} while (0);
}
void ArmatureComponentTest::onExit()
{
ArmatureDataManager::getInstance()->destroyInstance();
SceneReader::getInstance()->destroyInstance();
ActionManagerEx::getInstance()->destroyInstance();
GUIReader::shareReader()->purgeGUIReader();
SceneEditorTestLayer::onExit();
}
cocos2d::Node* ArmatureComponentTest::createGameScene()
{
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/ArmatureComponentTest/ArmatureComponentTest.json");
if (node == nullptr)
{
return nullptr;
}
Armature *pBlowFish = static_cast<Armature*>(node->getChildByTag(10007)->getComponent("Armature")->getNode());
pBlowFish->runAction(CCMoveBy::create(10.0f, Point(-1000.0f, 0)));
Armature *pButterflyfish = static_cast<Armature*>(node->getChildByTag(10008)->getComponent("Armature")->getNode());
pButterflyfish->runAction(CCMoveBy::create(10.0f, Point(-1000.0f, 0)));
return node;
}
UIComponentTest::UIComponentTest()
: _node(nullptr)
{
}
UIComponentTest::~UIComponentTest()
{
}
std::string UIComponentTest::title()
{
return "UI Component Test";
}
void UIComponentTest::onEnter()
{
SceneEditorTestLayer::onEnter();
bool bRet = false;
do
{
Node *root = createGameScene();
CC_BREAK_IF(!root);
this->addChild(root, 0, 1);
bRet = true;
} while (0);
}
void UIComponentTest::onExit()
{
ArmatureDataManager::getInstance()->destroyInstance();
SceneReader::getInstance()->destroyInstance();
ActionManagerEx::getInstance()->destroyInstance();
GUIReader::shareReader()->purgeGUIReader();
SceneEditorTestLayer::onExit();
}
cocos2d::Node* UIComponentTest::createGameScene()
{
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/UIComponentTest/UIComponentTest.json");
if (node == nullptr)
{
return nullptr;
}
_node = node;
cocos2d::gui::TouchGroup* touchGroup = static_cast<cocos2d::gui::TouchGroup*>(_node->getChildByTag(10025)->getComponent("GUIComponent")->getNode());
UIWidget* widget = static_cast<UIWidget*>(touchGroup->getWidgetByName("Panel_154"));
UIButton* button = static_cast<UIButton*>(widget->getChildByName("Button_156"));
button->addTouchEventListener(this, toucheventselector(UIComponentTest::touchEvent));
return node;
}
void UIComponentTest::touchEvent(CCObject *pSender, TouchEventType type)
{
switch (type)
{
case TOUCH_EVENT_BEGAN:
{
Armature *pBlowFish = static_cast<Armature*>(_node->getChildByTag(10010)->getComponent("Armature")->getNode());
pBlowFish->runAction(CCMoveBy::create(10.0f, ccp(-1000.0f, 0)));
Armature *pButterflyfish = static_cast<Armature*>(_node->getChildByTag(10011)->getComponent("Armature")->getNode());
pButterflyfish->runAction(CCMoveBy::create(10.0f, ccp(-1000.0f, 0)));
}
break;
default:
break;
}
}
TmxMapComponentTest::TmxMapComponentTest()
{
}
TmxMapComponentTest::~TmxMapComponentTest()
{
}
std::string TmxMapComponentTest::title()
{
return "TmxMap Component Test";
}
void TmxMapComponentTest::onEnter()
{
SceneEditorTestLayer::onEnter();
bool bRet = false;
do
{
Node *root = createGameScene();
CC_BREAK_IF(!root);
this->addChild(root, 0, 1);
bRet = true;
} while (0);
}
void TmxMapComponentTest::onExit()
{
ArmatureDataManager::getInstance()->destroyInstance();
SceneReader::getInstance()->destroyInstance();
ActionManagerEx::getInstance()->destroyInstance();
GUIReader::shareReader()->purgeGUIReader();
SceneEditorTestLayer::onExit();
}
cocos2d::Node* TmxMapComponentTest::createGameScene()
{
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/TmxMapComponentTest/TmxMapComponentTest.json");
if (node == nullptr)
{
return nullptr;
}
TMXTiledMap *tmxMap = static_cast<TMXTiledMap*>(node->getChildByTag(10015)->getComponent("TMXTiledMap")->getNode());
ActionInterval *actionTo = SkewTo::create(2, 0.f, 2.f);
ActionInterval *rotateTo = RotateTo::create(2, 61.0f);
ActionInterval *actionScaleTo = ScaleTo::create(2, -0.44f, 0.47f);
ActionInterval *actionScaleToBack = ScaleTo::create(2, 1.0f, 1.0f);
ActionInterval *rotateToBack = RotateTo::create(2, 0);
ActionInterval *actionToBack = SkewTo::create(2, 0, 0);
tmxMap->runAction(Sequence::create(actionTo, actionToBack, nullptr));
tmxMap->runAction(Sequence::create(rotateTo, rotateToBack, nullptr));
tmxMap->runAction(Sequence::create(actionScaleTo, actionScaleToBack, nullptr));
return node;
}
ParticleComponentTest::ParticleComponentTest()
{
}
ParticleComponentTest::~ParticleComponentTest()
{
}
std::string ParticleComponentTest::title()
{
return "Particle Component Test";
}
void ParticleComponentTest::onEnter()
{
SceneEditorTestLayer::onEnter();
bool bRet = false;
do
{
Node *root = createGameScene();
CC_BREAK_IF(!root);
this->addChild(root, 0, 1);
bRet = true;
} while (0);
}
void ParticleComponentTest::onExit()
{
ArmatureDataManager::getInstance()->destroyInstance();
SceneReader::getInstance()->destroyInstance();
ActionManagerEx::getInstance()->destroyInstance();
GUIReader::shareReader()->purgeGUIReader();
SceneEditorTestLayer::onExit();
}
cocos2d::Node* ParticleComponentTest::createGameScene()
{
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/ParticleComponentTest/ParticleComponentTest.json");
if (node == nullptr)
{
return nullptr;
}
ParticleSystemQuad* Particle = static_cast<ParticleSystemQuad*>(node->getChildByTag(10020)->getComponent("CCParticleSystemQuad")->getNode());
ActionInterval* jump = JumpBy::create(5, Point(-500,0), 50, 4);
FiniteTimeAction* action = Sequence::create( jump, jump->reverse(), nullptr);
Particle->runAction(action);
return node;
}
EffectComponentTest::EffectComponentTest()
: _node(nullptr)
{
}
EffectComponentTest::~EffectComponentTest()
{
}
std::string EffectComponentTest::title()
{
return "Effect Component Test";
}
void EffectComponentTest::onEnter()
{
SceneEditorTestLayer::onEnter();
bool bRet = false;
do
{
Node *root = createGameScene();
CC_BREAK_IF(!root);
this->addChild(root, 0, 1);
bRet = true;
} while (0);
}
void EffectComponentTest::onExit()
{
ArmatureDataManager::getInstance()->destroyInstance();
SceneReader::getInstance()->destroyInstance();
ActionManagerEx::getInstance()->destroyInstance();
GUIReader::shareReader()->purgeGUIReader();
SceneEditorTestLayer::onExit();
}
cocos2d::Node* EffectComponentTest::createGameScene()
{
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/EffectComponentTest/EffectComponentTest.json");
if (node == nullptr)
{
return nullptr;
}
_node = node;
Armature *pAr = static_cast<Armature*>(_node->getChildByTag(10015)->getComponent("Armature")->getNode());
pAr->getAnimation()->setMovementEventCallFunc(this, movementEvent_selector(EffectComponentTest::animationEvent));
return node;
}
void EffectComponentTest::animationEvent(Armature *armature, MovementEventType movementType, const std::string& movementID)
{
std::string id = movementID;
if (movementType == LOOP_COMPLETE)
{
if (id.compare("Fire") == 0)
{
ComAudio *pAudio = static_cast<ComAudio*>(_node->getChildByTag(10015)->getComponent("CCComAudio"));
pAudio->playEffect();
}
}
}
BackgroundComponentTest::BackgroundComponentTest()
{
}
BackgroundComponentTest::~BackgroundComponentTest()
{
}
std::string BackgroundComponentTest::title()
{
return "Background Component Test";
}
void BackgroundComponentTest::onEnter()
{
SceneEditorTestLayer::onEnter();
bool bRet = false;
do
{
Node *root = createGameScene();
CC_BREAK_IF(!root);
this->addChild(root, 0, 1);
bRet = true;
} while (0);
}
void BackgroundComponentTest::onExit()
{
ArmatureDataManager::getInstance()->destroyInstance();
SceneReader::getInstance()->destroyInstance();
ActionManagerEx::getInstance()->destroyInstance();
GUIReader::shareReader()->purgeGUIReader();
SceneEditorTestLayer::onExit();
}
cocos2d::Node* BackgroundComponentTest::createGameScene()
{
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/BackgroundComponentTest/BackgroundComponentTest.json");
if (node == nullptr)
{
return nullptr;
}
ActionManagerEx::getInstance()->playActionByName("startMenu_1.json","Animation1");
ComAudio *Audio = static_cast<ComAudio*>(node->getComponent("CCBackgroundAudio"));
Audio->playBackgroundMusic();
return node;
}
AttributeComponentTest::AttributeComponentTest()
: _node(nullptr)
{
}
AttributeComponentTest::~AttributeComponentTest()
{
}
std::string AttributeComponentTest::title()
{
return "Attribute Component Test";
}
void AttributeComponentTest::onEnter()
{
SceneEditorTestLayer::onEnter();
bool bRet = false;
do
{
Node *root = createGameScene();
CC_BREAK_IF(!root);
initData();
this->addChild(root, 0, 1);
bRet = true;
} while (0);
}
void AttributeComponentTest::onExit()
{
ArmatureDataManager::getInstance()->destroyInstance();
SceneReader::getInstance()->destroyInstance();
ActionManagerEx::getInstance()->destroyInstance();
GUIReader::shareReader()->purgeGUIReader();
SceneEditorTestLayer::onExit();
}
bool AttributeComponentTest::initData()
{
bool bRet = false;
unsigned long size = 0;
unsigned char *pBytes = nullptr;
rapidjson::Document jsonDict;
do {
CC_BREAK_IF(_node == nullptr);
ComAttribute *pAttribute = static_cast<ComAttribute*>(_node->getChildByTag(10015)->getComponent("CCComAttribute"));
CC_BREAK_IF(pAttribute == nullptr);
std::string jsonpath = FileUtils::getInstance()->fullPathForFilename(pAttribute->getJsonName());
std::string contentStr = FileUtils::getInstance()->getStringFromFile(jsonpath);
doc.Parse<0>(contentStr.c_str());
CC_BREAK_IF(doc.HasParseError());
std::string playerName = DICTOOL->getStringValue_json(jsonDict, "name");
float maxHP = DICTOOL->getFloatValue_json(jsonDict, "maxHP");
float maxMP = DICTOOL->getFloatValue_json(jsonDict, "maxMP");
pAttribute->setCString("Name", playerName.c_str());
pAttribute->setFloat("MaxHP", maxHP);
pAttribute->setFloat("MaxMP", maxMP);
log("Name: %s, HP: %f, MP: %f", pAttribute->getCString("Name"), pAttribute->getFloat("MaxHP"), pAttribute->getFloat("MaxMP"));
bRet = true;
} while (0);
return bRet;
}
void SceneEditorTestLayer::onEnter()
cocos2d::Node* AttributeComponentTest::createGameScene()
{
Layer::onEnter();
sendEvent(TRIGGEREVENT_ENTERSCENE);
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/AttributeComponentTest/AttributeComponentTest.json");
if (node == nullptr)
{
return nullptr;
}
_node = node;
return node;
}
TriggerTest::TriggerTest()
: _node(nullptr)
, _touchListener(nullptr)
{
}
TriggerTest::~TriggerTest()
{
}
std::string TriggerTest::title()
{
return "Trigger Test";
}
bool TriggerTest::init()
{
sendEvent(TRIGGEREVENT_INITSCENE);
return true;
}
// on "init" you need to initialize your instance
bool SceneEditorTestLayer::onEnter()
{
SceneEditorTestLayer::onEnter();
Node *root = createGameScene();
this->addChild(root, 0, 1);
this->schedule(schedule_selector(SceneEditorTestLayer::gameLogic));
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);
}
void SceneEditorTestLayer::onExit()
{
Layer::onExit();
sendEvent(TRIGGEREVENT_LEAVESCENE);
this->unschedule(schedule_selector(TriggerTest::gameLogic));
auto dispatcher = Director::getInstance()->getEventDispatcher();
dispatcher->removeEventListener(_touchListener);
Device::setAccelerometerEnabled(false);
ArmatureDataManager::getInstance()->destroyInstance();
SceneReader::getInstance()->destroyInstance();
ActionManagerEx::getInstance()->destroyInstance();
GUIReader::shareReader()->purgeGUIReader();
SceneEditorTestLayer::onExit();
}
bool SceneEditorTestLayer::onTouchBegan(Touch *touch, Event *unused_event)
@ -111,45 +823,15 @@ void SceneEditorTestLayer::gameLogic(float dt)
sendEvent(TRIGGEREVENT_UPDATESCENE);
}
static ActionObject* actionObject = nullptr;
cocos2d::Node* SceneEditorTestLayer::createGameScene()
{
Node *pNode = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/FishJoy2.json");
if (pNode == nullptr)
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/TriggerTest/TriggerTest.json");
if (node == nullptr)
{
return nullptr;
}
_curNode = pNode;
_node = node;
MenuItemFont *itemBack = MenuItemFont::create("Back", CC_CALLBACK_1(SceneEditorTestLayer::toExtensionsMainLayer, this));
itemBack->setColor(Color3B(255, 255, 255));
itemBack->setPosition(Point(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25));
Menu *menuBack = Menu::create(itemBack, nullptr);
menuBack->setPosition(Point(0.0f, 0.0f));
menuBack->setZOrder(4);
pNode->addChild(menuBack);
return pNode;
}
void SceneEditorTestLayer::toExtensionsMainLayer(cocos2d::Object *sender)
{
if (actionObject)
{
actionObject->stop();
}
ComAudio *pBackMusic = (ComAudio*)(_curNode->getComponent("CCBackgroundAudio"));
pBackMusic->stopBackgroundMusic();
ExtensionsTestScene *pScene = new ExtensionsTestScene();
pScene->runThisTest();
pScene->release();
}
void runSceneEditorTestLayer()
{
Scene *pScene = SceneEditorTestLayer::scene();
Director::getInstance()->replaceScene(pScene);
return node;
}

View File

@ -4,23 +4,183 @@
#include "cocos2d.h"
#include "extensions/cocos-ext.h"
void runSceneEditorTestLayer();
class SceneEditorTestScene : public TestScene
{
public:
SceneEditorTestScene(bool bPortrait = false);
virtual void runThisTest();
// The CallBack for back to the main menu scene
virtual void MainMenuCallback(cocos2d::Object* pSender);
};
enum {
TEST_LOADSCENEEDITORFILE = 0,
TEST_SPIRTECOMPONENT,
TEST_ARMATURECOMPONENT,
TEST_UICOMPONENT,
TEST_TMXMAPCOMPONENT,
TEST_PARTICLECOMPONENT,
TEST_EFEECTCOMPONENT,
TEST_BACKGROUNDCOMPONENT,
TEST_ATTRIBUTECOMPONENT,
TEST_TRIGGER,
TEST_SCENEEDITOR_COUNT
};
class SceneEditorTestLayer : public cocos2d::Layer
{
public:
SceneEditorTestLayer();
~SceneEditorTestLayer();
// Here's a difference. Method 'init' in cocos2d-x returns bool,
// instead of returning 'id' in cocos2d-iphone
virtual bool init();
// callback of Scene Enter
virtual void onEnter();
// callback of Scene Exit
virtual void onExit();
virtual std::string title();
virtual std::string subtitle();
virtual void restartCallback(cocos2d::Object* pSender);
virtual void nextCallback(cocos2d::Object* pSender);
virtual void backCallback(cocos2d::Object* pSender);
virtual void draw();
protected:
MenuItemImage *restartItem;
MenuItemImage *nextItem;
MenuItemImage *backItem;
};
class loadSceneEdtiorFileTest : public SceneEditorTestLayer
{
public:
loadSceneEdtiorFileTest();
~loadSceneEdtiorFileTest();
virtual std::string title();
virtual void onEnter();
virtual void onExit();
cocos2d::Node* createGameScene();
};
class SpriteComponentTest : public SceneEditorTestLayer
{
public:
SpriteComponentTest();
~SpriteComponentTest();
virtual std::string title();
virtual void onEnter();
virtual void onExit();
cocos2d::Node* createGameScene();
};
class ArmatureComponentTest : public SceneEditorTestLayer
{
public:
ArmatureComponentTest();
~ArmatureComponentTest();
virtual std::string title();
virtual void onEnter();
virtual void onExit();
cocos2d::Node* createGameScene();
};
class UIComponentTest : public SceneEditorTestLayer
{
public:
UIComponentTest();
~UIComponentTest();
virtual std::string title();
virtual void onEnter();
virtual void onExit();
cocos2d::Node* createGameScene();
void touchEvent(cocos2d::Object *pSender, cocos2d::gui::TouchEventType type);
private:
cocos2d::Node* _node;
};
class TmxMapComponentTest : public SceneEditorTestLayer
{
public:
TmxMapComponentTest();
~TmxMapComponentTest();
virtual std::string title();
virtual void onEnter();
virtual void onExit();
cocos2d::Node* createGameScene();
};
class ParticleComponentTest : public SceneEditorTestLayer
{
public:
ParticleComponentTest();
~ParticleComponentTest();
virtual std::string title();
virtual void onEnter();
virtual void onExit();
cocos2d::Node* createGameScene();
};
class EffectComponentTest : public SceneEditorTestLayer
{
public:
EffectComponentTest();
~EffectComponentTest();
virtual std::string title();
virtual void onEnter();
virtual void onExit();
cocos2d::Node* createGameScene();
void animationEvent(cocostudio::Armature *armature, cocostudio::MovementEventType movementType, const std::string& movementID);
private:
cocos2d::Node* _node;
};
class BackgroundComponentTest : public SceneEditorTestLayer
{
public:
BackgroundComponentTest();
~BackgroundComponentTest();
virtual std::string title();
virtual void onEnter();
virtual void onExit();
cocos2d::Node* createGameScene();
};
class AttributeComponentTest : public SceneEditorTestLayer
{
public:
AttributeComponentTest();
~AttributeComponentTest();
virtual std::string title();
virtual void onEnter();
virtual void onExit();
bool initData();
cocos2d::Node* createGameScene();
private:
cocos2d::Node* _node;
};
class TriggerTest : public SceneEditorTestLayer
{
public:
TriggerTest();
~TriggerTest();
virtual std::string title();
virtual bool init();
virtual void onEnter();
virtual void onExit();
// default implements are used to call script callback if exist
virtual bool onTouchBegan(Touch *touch, Event *unused_event);
@ -31,20 +191,11 @@ public:
// update of game
void gameLogic(float dt);
// there's no 'id' in cpp, so we recommand to return the exactly class pointer
static cocos2d::Scene* scene();
// implement the "static node()" method manually
CREATE_FUNC(SceneEditorTestLayer);
// init scene
// create scene
cocos2d::Node* createGameScene();
//back to Extensions Main Layer
void toExtensionsMainLayer(cocos2d::Object *sender);
private:
cocos2d::Node *_curNode;
cocos2d::Node *_node;
cocos2d::EventListener* _touchListener;
};

View File

@ -7,7 +7,7 @@ using namespace cocostudio;
IMPLEMENT_CLASS_INFO(PlayMusic)
PlayMusic::PlayMusic(void)
:_nTag(-1)
:_tag(-1)
{
}
@ -24,15 +24,15 @@ void PlayMusic::done()
{
do
{
Node *pNode = SceneReader::getInstance()->getNodeByTag(_nTag);
Node *pNode = SceneReader::getInstance()->getNodeByTag(_tag);
CC_BREAK_IF(pNode == nullptr);
ComAudio *audio = (ComAudio*)(pNode->getComponent(_comName.c_str()));
CC_BREAK_IF(audio == nullptr);
if (_nType == 0)
if (_type == 0)
{
audio->playBackgroundMusic();
}
else if (_nType == 1)
else if (_type == 1)
{
audio->playEffect();
}
@ -49,7 +49,7 @@ void PlayMusic::serialize(const rapidjson::Value &val)
std::string key = DICTOOL->getStringValue_json(subDict, "key");
if (key == "Tag")
{
_nTag = DICTOOL->getIntValue_json(subDict, "value");
_tag = DICTOOL->getIntValue_json(subDict, "value");
continue;
}
else if (key == "componentName")
@ -59,7 +59,7 @@ void PlayMusic::serialize(const rapidjson::Value &val)
}
else if (key == "type")
{
_nType = DICTOOL->getIntValue_json(subDict, "value");
_type = DICTOOL->getIntValue_json(subDict, "value");
continue;
}
}
@ -71,8 +71,8 @@ void PlayMusic::removeAll()
IMPLEMENT_CLASS_INFO(TMoveTo)
TMoveTo::TMoveTo(void)
:_nTag(-1)
,_fDuration(0.0f)
:_tag(-1)
,_duration(0.0f)
{
}
@ -89,9 +89,9 @@ void TMoveTo::done()
{
do
{
Node *pNode = SceneReader::getInstance()->getNodeByTag(_nTag);
Node *pNode = SceneReader::getInstance()->getNodeByTag(_tag);
CC_BREAK_IF(pNode == nullptr);
ActionInterval* actionTo = MoveTo::create(_fDuration, _pos);
ActionInterval* actionTo = MoveTo::create(_duration, _pos);
CC_BREAK_IF(actionTo == nullptr);
pNode->runAction(actionTo);
} while (0);
@ -106,12 +106,12 @@ void TMoveTo::serialize(const rapidjson::Value &val)
std::string key = DICTOOL->getStringValue_json(subDict, "key");
if (key == "Tag")
{
_nTag = DICTOOL->getIntValue_json(subDict, "value");
_tag = DICTOOL->getIntValue_json(subDict, "value");
continue;
}
else if (key == "Duration")
{
_fDuration = DICTOOL->getFloatValue_json(subDict, "value");
_duration = DICTOOL->getFloatValue_json(subDict, "value");
continue;
}
else if (key == "x")
@ -129,13 +129,15 @@ void TMoveTo::serialize(const rapidjson::Value &val)
void TMoveTo::removeAll()
{
Node *node = SceneReader::getInstance()->getNodeByTag(_tag);
node->getActionManager()->removeAllActions();
}
IMPLEMENT_CLASS_INFO(TMoveBy)
TMoveBy::TMoveBy(void)
:_nTag(-1)
,_fDuration(0.0f)
,_bReverse(false)
:_tag(-1)
,_duration(0.0f)
,_reverse(false)
{
}
@ -152,11 +154,11 @@ void TMoveBy::done()
{
do
{
Node *pNode = SceneReader::getInstance()->getNodeByTag(_nTag);
Node *pNode = SceneReader::getInstance()->getNodeByTag(_tag);
CC_BREAK_IF(pNode == nullptr);
ActionInterval* actionBy = MoveBy::create(_fDuration, _pos);
ActionInterval* actionBy = MoveBy::create(_duration, _pos);
CC_BREAK_IF(actionBy == nullptr);
if (_bReverse == true)
if (_reverse == true)
{
ActionInterval* actionByBack = actionBy->reverse();
pNode->runAction( CCSequence::create(actionBy, actionByBack, nullptr));
@ -177,12 +179,12 @@ void TMoveBy::serialize(const rapidjson::Value &val)
std::string key = DICTOOL->getStringValue_json(subDict, "key");
if (key == "Tag")
{
_nTag = DICTOOL->getIntValue_json(subDict, "value");
_tag = DICTOOL->getIntValue_json(subDict, "value");
continue;
}
else if (key == "Duration")
{
_fDuration = DICTOOL->getFloatValue_json(subDict, "value");
_duration = DICTOOL->getFloatValue_json(subDict, "value");
continue;
}
else if (key == "x")
@ -197,7 +199,7 @@ void TMoveBy::serialize(const rapidjson::Value &val)
}
else if (key == "IsReverse")
{
_bReverse = (bool)(DICTOOL->getIntValue_json(subDict, "value"));
_reverse = (bool)(DICTOOL->getIntValue_json(subDict, "value"));
continue;
}
}
@ -205,16 +207,17 @@ void TMoveBy::serialize(const rapidjson::Value &val)
void TMoveBy::removeAll()
{
CCLOG("TMoveBy::removeAll");
Node *node = SceneReader::getInstance()->getNodeByTag(_tag);
node->getActionManager()->removeAllActions();
}
IMPLEMENT_CLASS_INFO(TRotateTo)
TRotateTo::TRotateTo(void)
: _nTag(-1)
, _fDuration(0.0f)
, _fDeltaAngle(0.0f)
: _tag(-1)
, _duration(0.0f)
, _deltaAngle(0.0f)
{
}
@ -231,9 +234,9 @@ void TRotateTo::done()
{
do
{
Node *pNode = SceneReader::getInstance()->getNodeByTag(_nTag);
Node *pNode = SceneReader::getInstance()->getNodeByTag(_tag);
CC_BREAK_IF(pNode == nullptr);
ActionInterval* actionTo = RotateTo::create(_fDuration, _fDeltaAngle);
ActionInterval* actionTo = RotateTo::create(_duration, _deltaAngle);
CC_BREAK_IF(actionTo == nullptr);
pNode->runAction(actionTo);
} while (0);
@ -248,17 +251,17 @@ void TRotateTo::serialize(const rapidjson::Value &val)
std::string key = DICTOOL->getStringValue_json(subDict, "key");
if (key == "Tag")
{
_nTag = DICTOOL->getIntValue_json(subDict, "value");
_tag = DICTOOL->getIntValue_json(subDict, "value");
continue;
}
else if (key == "Duration")
{
_fDuration = DICTOOL->getFloatValue_json(subDict, "value");
_duration = DICTOOL->getFloatValue_json(subDict, "value");
continue;
}
else if (key == "DeltaAngle")
{
_fDeltaAngle = DICTOOL->getFloatValue_json(subDict, "value");
_deltaAngle = DICTOOL->getFloatValue_json(subDict, "value");
continue;
}
}
@ -266,17 +269,18 @@ void TRotateTo::serialize(const rapidjson::Value &val)
void TRotateTo::removeAll()
{
CCLOG("TRotateTo::removeAll");
Node *node = SceneReader::getInstance()->getNodeByTag(_tag);
node->getActionManager()->removeAllActions();
}
IMPLEMENT_CLASS_INFO(TRotateBy)
TRotateBy::TRotateBy(void)
: _nTag(-1)
, _fDuration(0.0f)
, _fDeltaAngle(0.0f)
, _bReverse(false)
: _tag(-1)
, _duration(0.0f)
, _deltaAngle(0.0f)
, _reverse(false)
{
}
@ -293,11 +297,11 @@ void TRotateBy::done()
{
do
{
Node *pNode = SceneReader::getInstance()->getNodeByTag(_nTag);
Node *pNode = SceneReader::getInstance()->getNodeByTag(_tag);
CC_BREAK_IF(pNode == nullptr);
ActionInterval* actionBy = RotateBy::create(_fDuration, _fDeltaAngle);
ActionInterval* actionBy = RotateBy::create(_duration, _deltaAngle);
CC_BREAK_IF(actionBy == nullptr);
if (_bReverse == true)
if (_reverse == true)
{
ActionInterval* actionByBack = actionBy->reverse();
pNode->runAction( Sequence::create(actionBy, actionByBack, nullptr));
@ -318,22 +322,22 @@ void TRotateBy::serialize(const rapidjson::Value &val)
std::string key = DICTOOL->getStringValue_json(subDict, "key");
if (key == "Tag")
{
_nTag = DICTOOL->getIntValue_json(subDict, "value");
_tag = DICTOOL->getIntValue_json(subDict, "value");
continue;
}
else if (key == "Duration")
{
_fDuration = DICTOOL->getFloatValue_json(subDict, "value");
_duration = DICTOOL->getFloatValue_json(subDict, "value");
continue;
}
else if (key == "DeltaAngle")
{
_fDeltaAngle = DICTOOL->getFloatValue_json(subDict, "value");
_deltaAngle = DICTOOL->getFloatValue_json(subDict, "value");
continue;
}
else if (key == "IsReverse")
{
_bReverse = (int)(DICTOOL->getIntValue_json(subDict, "value"));
_reverse = (int)(DICTOOL->getIntValue_json(subDict, "value"));
continue;
}
}
@ -341,15 +345,16 @@ void TRotateBy::serialize(const rapidjson::Value &val)
void TRotateBy::removeAll()
{
CCLOG("TRotateBy::removeAll");
Node *node = SceneReader::getInstance()->getNodeByTag(_tag);
node->getActionManager()->removeAllActions();
}
IMPLEMENT_CLASS_INFO(TScaleTo)
TScaleTo::TScaleTo(void)
: _nTag(-1)
, _fDuration(0.0f)
: _tag(-1)
, _duration(0.0f)
{
}
@ -366,9 +371,9 @@ void TScaleTo::done()
{
do
{
Node *pNode = SceneReader::getInstance()->getNodeByTag(_nTag);
Node *pNode = SceneReader::getInstance()->getNodeByTag(_tag);
CC_BREAK_IF(pNode == nullptr);
ActionInterval* actionTo = ScaleTo::create(_fDuration, _scale.x, _scale.y);
ActionInterval* actionTo = ScaleTo::create(_duration, _scale.x, _scale.y);
CC_BREAK_IF(actionTo == nullptr);
pNode->runAction(actionTo);
} while (0);
@ -383,12 +388,12 @@ void TScaleTo::serialize(const rapidjson::Value &val)
std::string key = DICTOOL->getStringValue_json(subDict, "key");
if (key == "Tag")
{
_nTag = DICTOOL->getIntValue_json(subDict, "value");
_tag = DICTOOL->getIntValue_json(subDict, "value");
continue;
}
else if (key == "Duration")
{
_fDuration = DICTOOL->getFloatValue_json(subDict, "value");
_duration = DICTOOL->getFloatValue_json(subDict, "value");
continue;
}
else if (key == "ScaleX")
@ -406,16 +411,17 @@ void TScaleTo::serialize(const rapidjson::Value &val)
void TScaleTo::removeAll()
{
CCLOG("TScaleTo::removeAll");
Node *node = SceneReader::getInstance()->getNodeByTag(_tag);
node->getActionManager()->removeAllActions();
}
IMPLEMENT_CLASS_INFO(TScaleBy)
TScaleBy::TScaleBy(void)
: _nTag(-1)
, _fDuration(0.0f)
, _bReverse(false)
: _tag(-1)
, _duration(0.0f)
, _reverse(false)
{
}
@ -432,11 +438,11 @@ void TScaleBy::done()
{
do
{
Node *pNode = SceneReader::getInstance()->getNodeByTag(_nTag);
Node *pNode = SceneReader::getInstance()->getNodeByTag(_tag);
CC_BREAK_IF(pNode == nullptr);
ActionInterval* actionBy = ScaleBy::create(_fDuration, _scale.x, _scale.y);
ActionInterval* actionBy = ScaleBy::create(_duration, _scale.x, _scale.y);
CC_BREAK_IF(actionBy == nullptr);
if (_bReverse == true)
if (_reverse == true)
{
ActionInterval* actionByBack = actionBy->reverse();
pNode->runAction(Sequence::create(actionBy, actionByBack, nullptr));
@ -457,12 +463,12 @@ void TScaleBy::serialize(const rapidjson::Value &val)
std::string key = DICTOOL->getStringValue_json(subDict, "key");
if (key == "Tag")
{
_nTag = DICTOOL->getIntValue_json(subDict, "value");
_tag = DICTOOL->getIntValue_json(subDict, "value");
continue;
}
else if (key == "Duration")
{
_fDuration = DICTOOL->getFloatValue_json(subDict, "value");
_duration = DICTOOL->getFloatValue_json(subDict, "value");
continue;
}
else if (key == "ScaleX")
@ -477,7 +483,7 @@ void TScaleBy::serialize(const rapidjson::Value &val)
}
else if (key == "IsReverse")
{
_bReverse = (bool)(DICTOOL->getIntValue_json(subDict, "value"));
_reverse = (bool)(DICTOOL->getIntValue_json(subDict, "value"));
continue;
}
}
@ -485,15 +491,16 @@ void TScaleBy::serialize(const rapidjson::Value &val)
void TScaleBy::removeAll()
{
CCLOG("TScaleBy::removeAll");
Node *node = SceneReader::getInstance()->getNodeByTag(_tag);
node->getActionManager()->removeAllActions();
}
IMPLEMENT_CLASS_INFO(TSkewTo)
TSkewTo::TSkewTo(void)
: _nTag(-1)
, _fDuration(0.0f)
: _tag(-1)
, _duration(0.0f)
{
}
@ -510,9 +517,9 @@ void TSkewTo::done()
{
do
{
Node *pNode = SceneReader::getInstance()->getNodeByTag(_nTag);
Node *pNode = SceneReader::getInstance()->getNodeByTag(_tag);
CC_BREAK_IF(pNode == nullptr);
ActionInterval* actionTo = SkewTo::create(_fDuration, _skew.x, _skew.y);
ActionInterval* actionTo = SkewTo::create(_duration, _skew.x, _skew.y);
CC_BREAK_IF(actionTo == nullptr);
pNode->runAction(actionTo);
} while (0);
@ -527,12 +534,12 @@ void TSkewTo::serialize(const rapidjson::Value &val)
std::string key = DICTOOL->getStringValue_json(subDict, "key");
if (key == "Tag")
{
_nTag = DICTOOL->getIntValue_json(subDict, "value");
_tag = DICTOOL->getIntValue_json(subDict, "value");
continue;
}
else if (key == "Duration")
{
_fDuration = DICTOOL->getFloatValue_json(subDict, "value");
_duration = DICTOOL->getFloatValue_json(subDict, "value");
continue;
}
else if (key == "SkewX")
@ -550,16 +557,17 @@ void TSkewTo::serialize(const rapidjson::Value &val)
void TSkewTo::removeAll()
{
CCLOG("TSkewTo::removeAll");
Node *node = SceneReader::getInstance()->getNodeByTag(_tag);
node->getActionManager()->removeAllActions();
}
IMPLEMENT_CLASS_INFO(TSkewBy)
TSkewBy::TSkewBy(void)
: _nTag(-1)
, _fDuration(0.0f)
, _bReverse(false)
: _tag(-1)
, _duration(0.0f)
, _reverse(false)
{
}
@ -576,11 +584,11 @@ void TSkewBy::done()
{
do
{
Node *pNode = SceneReader::getInstance()->getNodeByTag(_nTag);
Node *pNode = SceneReader::getInstance()->getNodeByTag(_tag);
CC_BREAK_IF(pNode == nullptr);
ActionInterval* actionBy = SkewBy::create(_fDuration, _skew.x, _skew.y);
ActionInterval* actionBy = SkewBy::create(_duration, _skew.x, _skew.y);
CC_BREAK_IF(actionBy == nullptr);
if (_bReverse == true)
if (_reverse == true)
{
ActionInterval* actionByBack = actionBy->reverse();
pNode->runAction(Sequence::create(actionBy, actionByBack, nullptr));
@ -601,12 +609,12 @@ void TSkewBy::serialize(const rapidjson::Value &val)
std::string key = DICTOOL->getStringValue_json(subDict, "key");
if (key == "Tag")
{
_nTag = DICTOOL->getIntValue_json(subDict, "value");
_tag = DICTOOL->getIntValue_json(subDict, "value");
continue;
}
else if (key == "Duration")
{
_fDuration = DICTOOL->getFloatValue_json(subDict, "value");
_duration = DICTOOL->getFloatValue_json(subDict, "value");
continue;
}
else if (key == "SKewX")
@ -621,22 +629,23 @@ void TSkewBy::serialize(const rapidjson::Value &val)
}
else if (key == "IsReverse")
{
_bReverse = (bool)(DICTOOL->getIntValue_json(subDict, "value"));
_reverse = (bool)(DICTOOL->getIntValue_json(subDict, "value"));
}
}
}
void TSkewBy::removeAll()
{
CCLOG("TSkewBy::removeAll");
Node *node = SceneReader::getInstance()->getNodeByTag(_tag);
node->getActionManager()->removeAllActions();
}
IMPLEMENT_CLASS_INFO(TriggerState)
TriggerState::TriggerState(void)
:_nID(-1)
,_nState(0)
:_id(-1)
,_state(0)
{
}
@ -651,20 +660,20 @@ bool TriggerState::init()
void TriggerState::done()
{
TriggerObj *obj = TriggerMng::getInstance()->getTriggerObj(_nID);
TriggerObj *obj = TriggerMng::getInstance()->getTriggerObj(_id);
if (obj != nullptr)
{
if (_nState == 0)
if (_state == 0)
{
obj->setEnabled(false);
}
else if (_nState == 1)
else if (_state == 1)
{
obj->setEnabled(true);
}
else if (_nState == 2)
else if (_state == 2)
{
TriggerMng::getInstance()->removeTriggerObj(_nID);
TriggerMng::getInstance()->removeTriggerObj(_id);
}
}
@ -680,12 +689,12 @@ void TriggerState::serialize(const rapidjson::Value &val)
std::string key = DICTOOL->getStringValue_json(subDict, "key");
if (key == "ID")
{
_nID = DICTOOL->getIntValue_json(subDict, "value");
_id = DICTOOL->getIntValue_json(subDict, "value");
continue;
}
else if (key == "State")
{
_nState = DICTOOL->getIntValue_json(subDict, "value");
_state = DICTOOL->getIntValue_json(subDict, "value");
continue;
}
}
@ -698,7 +707,7 @@ void TriggerState::removeAll()
IMPLEMENT_CLASS_INFO(ArmaturePlayAction)
ArmaturePlayAction::ArmaturePlayAction(void)
: _nTag(-1)
: _tag(-1)
{
}
@ -715,7 +724,7 @@ void ArmaturePlayAction::done()
{
do
{
Node *pNode = SceneReader::getInstance()->getNodeByTag(_nTag);
Node *pNode = SceneReader::getInstance()->getNodeByTag(_tag);
CC_BREAK_IF(pNode == nullptr);
ComRender *pRender = (ComRender*)(pNode->getComponent(_ComName.c_str()));
CC_BREAK_IF(pRender == nullptr);
@ -734,7 +743,7 @@ void ArmaturePlayAction::serialize(const rapidjson::Value &val)
std::string key = DICTOOL->getStringValue_json(subDict, "key");
if (key == "Tag")
{
_nTag = DICTOOL->getIntValue_json(subDict, "value");
_tag = DICTOOL->getIntValue_json(subDict, "value");
continue;
}
else if (key == "componentName")

View File

@ -17,9 +17,9 @@ public:
virtual void serialize(const rapidjson::Value &val);
virtual void removeAll();
private:
int _nTag;
int _tag;
std::string _comName;
int _nType;
int _type;
};
class TMoveTo: public cocostudio::BaseTriggerAction
@ -34,8 +34,8 @@ public:
virtual void serialize(const rapidjson::Value &val);
virtual void removeAll();
private:
int _nTag;
float _fDuration;
int _tag;
float _duration;
cocos2d::Point _pos;
};
@ -52,10 +52,10 @@ public:
virtual void serialize(const rapidjson::Value &val);
virtual void removeAll();
private:
int _nTag;
float _fDuration;
int _tag;
float _duration;
cocos2d::Point _pos;
bool _bReverse;
bool _reverse;
};
@ -71,9 +71,9 @@ public:
virtual void serialize(const rapidjson::Value &val);
virtual void removeAll();
private:
int _nTag;
float _fDuration;
float _fDeltaAngle;
int _tag;
float _duration;
float _deltaAngle;
};
@ -89,10 +89,10 @@ public:
virtual void serialize(const rapidjson::Value &val);
virtual void removeAll();
private:
int _nTag;
float _fDuration;
float _fDeltaAngle;
bool _bReverse;
int _tag;
float _duration;
float _deltaAngle;
bool _reverse;
};
@ -108,8 +108,8 @@ public:
virtual void serialize(const rapidjson::Value &val);
virtual void removeAll();
private:
int _nTag;
float _fDuration;
int _tag;
float _duration;
cocos2d::Point _scale;
};
@ -126,10 +126,10 @@ public:
virtual void serialize(const rapidjson::Value &val);
virtual void removeAll();
private:
int _nTag;
float _fDuration;
int _tag;
float _duration;
cocos2d::Point _scale;
bool _bReverse;
bool _reverse;
};
@ -146,8 +146,8 @@ public:
virtual void serialize(const rapidjson::Value &val);
virtual void removeAll();
private:
int _nTag;
float _fDuration;
int _tag;
float _duration;
cocos2d::Point _skew;
};
@ -164,10 +164,10 @@ public:
virtual void serialize(const rapidjson::Value &val);
virtual void removeAll();
private:
int _nTag;
float _fDuration;
int _tag;
float _duration;
cocos2d::Point _skew;
bool _bReverse;
bool _reverse;
};
@ -183,8 +183,8 @@ public:
virtual void serialize(const rapidjson::Value &val);
virtual void removeAll();
private:
int _nID;
int _nState;
int _id;
int _state;
};
class ArmaturePlayAction : public cocostudio::BaseTriggerAction
@ -199,7 +199,7 @@ public:
virtual void serialize(const rapidjson::Value &val);
virtual void removeAll();
private:
int _nTag;
int _tag;
std::string _ComName;
std::string _aniname;
};

View File

@ -8,29 +8,29 @@ using namespace cocostudio;
IMPLEMENT_CLASS_INFO(TimeElapsed)
TimeElapsed::TimeElapsed(void)
:_fTotalTime(0.0f)
,_fTmpTime(0.0f)
,_pScheduler(nullptr)
,_bSuc(false)
:_totalTime(0.0f)
,_tmpTime(0.0f)
,_scheduler(nullptr)
,_suc(false)
{
_pScheduler = Director::getInstance()->getScheduler();
_pScheduler->retain();
_scheduler = Director::getInstance()->getScheduler();
_scheduler->retain();
}
TimeElapsed::~TimeElapsed(void)
{
CC_SAFE_RELEASE(_pScheduler);
CC_SAFE_RELEASE(_scheduler);
}
bool TimeElapsed::init()
{
_pScheduler->scheduleSelector(schedule_selector(TimeElapsed::update), this, 0.0f , kRepeatForever, 0.0f, false);
_scheduler->scheduleSelector(schedule_selector(TimeElapsed::update), this, 0.0f , kRepeatForever, 0.0f, false);
return true;
}
bool TimeElapsed::detect()
{
return _bSuc;
return _suc;
}
void TimeElapsed::serialize(const rapidjson::Value &val)
@ -42,31 +42,31 @@ void TimeElapsed::serialize(const rapidjson::Value &val)
std::string key = DICTOOL->getStringValue_json(subDict, "key");
if (key == "TotalTime")
{
_fTotalTime = DICTOOL->getFloatValue_json(subDict, "value");
_totalTime = DICTOOL->getFloatValue_json(subDict, "value");
}
}
}
void TimeElapsed::removeAll()
{
_pScheduler->unscheduleUpdateForTarget(this);
_scheduler->unscheduleUpdateForTarget(this);
}
void TimeElapsed::update(float dt)
{
_fTmpTime += dt;
if (_fTmpTime > _fTotalTime)
_tmpTime += dt;
if (_tmpTime > _totalTime)
{
_fTmpTime = 0.0f;
_bSuc = true;
_tmpTime = 0.0f;
_suc = true;
}
}
IMPLEMENT_CLASS_INFO(ArmatureActionState)
ArmatureActionState::ArmatureActionState(void)
: _nTag(-1)
, _nState(-1)
, _bSuc(false)
: _tag(-1)
, _state(-1)
, _suc(false)
{
}
@ -78,7 +78,7 @@ bool ArmatureActionState::init()
{
do
{
Node *pNode = SceneReader::getInstance()->getNodeByTag(_nTag);
Node *pNode = SceneReader::getInstance()->getNodeByTag(_tag);
CC_BREAK_IF(pNode == nullptr);
ComRender *pRender = (ComRender*)(pNode->getComponent(_comName.c_str()));
CC_BREAK_IF(pRender == nullptr);
@ -92,7 +92,7 @@ bool ArmatureActionState::init()
bool ArmatureActionState::detect()
{
return _bSuc;
return _suc;
}
void ArmatureActionState::serialize(const rapidjson::Value &val)
@ -104,7 +104,7 @@ void ArmatureActionState::serialize(const rapidjson::Value &val)
std::string key = DICTOOL->getStringValue_json(subDict, "key");
if (key == "Tag")
{
_nTag = DICTOOL->getIntValue_json(subDict, "value");
_tag = DICTOOL->getIntValue_json(subDict, "value");
continue;
}
else if (key == "componentName")
@ -119,7 +119,7 @@ void ArmatureActionState::serialize(const rapidjson::Value &val)
}
else if (key == "ActionType")
{
_nState = DICTOOL->getIntValue_json(subDict, "value");
_state = DICTOOL->getIntValue_json(subDict, "value");
continue;
}
}
@ -129,7 +129,7 @@ void ArmatureActionState::removeAll()
{
do
{
Node *pNode = SceneReader::getInstance()->getNodeByTag(_nTag);
Node *pNode = SceneReader::getInstance()->getNodeByTag(_tag);
CC_BREAK_IF(pNode == nullptr);
ComRender *pRender = (ComRender*)(pNode->getComponent(_comName.c_str()));
CC_BREAK_IF(pRender == nullptr);
@ -142,15 +142,15 @@ void ArmatureActionState::removeAll()
void ArmatureActionState::animationEvent(cocostudio::Armature *armature, cocostudio::MovementEventType movementType, const std::string& movementID)
{
std::string id = movementID;
if (movementType == _nState && id.compare(_aniname) == 0)
if (movementType == _state && id.compare(_aniname) == 0)
{
_bSuc = true;
_suc = true;
}
}
IMPLEMENT_CLASS_INFO(NodeInRect)
NodeInRect::NodeInRect(void)
:_nTag(-1)
:_tag(-1)
{
}
@ -166,7 +166,7 @@ bool NodeInRect::init()
bool NodeInRect::detect()
{
Node *pNode = SceneReader::getInstance()->getNodeByTag(_nTag);
Node *pNode = SceneReader::getInstance()->getNodeByTag(_tag);
if (pNode != nullptr && abs(pNode->getPositionX() - _origin.x) <= _size.width && abs(pNode->getPositionY() - _origin.y) <= _size.height)
{
return true;
@ -183,7 +183,7 @@ void NodeInRect::serialize(const rapidjson::Value &val)
std::string key = DICTOOL->getStringValue_json(subDict, "key");
if (key == "Tag")
{
_nTag = DICTOOL->getIntValue_json(subDict, "value");
_tag = DICTOOL->getIntValue_json(subDict, "value");
continue;
}
else if (key == "originX")
@ -217,8 +217,8 @@ void NodeInRect::removeAll()
IMPLEMENT_CLASS_INFO(NodeVisible)
NodeVisible::NodeVisible(void)
: _nTag(-1)
, _bVisible(false)
: _tag(-1)
, _visible(false)
{
}
@ -233,8 +233,8 @@ bool NodeVisible::init()
bool NodeVisible::detect()
{
Node *pNode = SceneReader::getInstance()->getNodeByTag(_nTag);
if (pNode != nullptr && pNode->isVisible() == _bVisible)
Node *pNode = SceneReader::getInstance()->getNodeByTag(_tag);
if (pNode != nullptr && pNode->isVisible() == _visible)
{
return true;
}
@ -250,12 +250,12 @@ void NodeVisible::serialize(const rapidjson::Value &val)
std::string key = DICTOOL->getStringValue_json(subDict, "key");
if (key == "Tag")
{
_nTag = DICTOOL->getIntValue_json(subDict, "value");
_tag = DICTOOL->getIntValue_json(subDict, "value");
continue;
}
else if (key == "Visible")
{
_bVisible = DICTOOL->getIntValue_json(subDict, "value");
_visible = DICTOOL->getIntValue_json(subDict, "value");
continue;
}
}

View File

@ -18,10 +18,10 @@ public:
virtual void removeAll();
virtual void update(float dt);
private:
float _fTotalTime;
float _fTmpTime;
cocos2d::Scheduler *_pScheduler;
bool _bSuc;
float _totalTime;
float _tmpTime;
cocos2d::Scheduler *_scheduler;
bool _suc;
};
@ -38,11 +38,11 @@ public:
virtual void removeAll();
void animationEvent(cocostudio::Armature *armature, cocostudio::MovementEventType movementType, const std::string& movementID);
private:
int _nTag;
int _tag;
std::string _comName;
std::string _aniname;
int _nState;
bool _bSuc;
int _state;
bool _suc;
};
@ -58,7 +58,7 @@ public:
virtual void serialize(const rapidjson::Value &val);
virtual void removeAll();
private:
int _nTag;
int _tag;
cocos2d::Point _origin;
cocos2d::Size _size;
};
@ -75,8 +75,8 @@ public:
virtual void serialize(const rapidjson::Value &val);
virtual void removeAll();
private:
int _nTag;
bool _bVisible;
int _tag;
bool _visible;
};