void ParticleComponentTest::defaultPlay() { ComRender* Particle = static_cast<ComRender*>(_rootNode->getChildByTag(10020)->getComponent("CCParticleSystemQuad")); ActionInterval* jump = CCJumpBy::create(5, Point(-500,0), 50, 4); FiniteTimeAction* action = CCSequence::create( jump, jump->reverse(), nullptr); Particle->getNode()->runAction(action); }
void UIComponentTest::defaultPlay() { ComRender *render = static_cast<ComRender*>(_rootNode->getChildByTag(10025)->getComponent("GUIComponent")); 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)); }
void ArmatureComponentTest::defaultPlay() { ComRender *pBlowFish = static_cast<ComRender*>(_rootNode->getChildByTag(10007)->getComponent("CCArmature")); pBlowFish->getNode()->runAction(MoveBy::create(10.0f, Point(-1000.0f, 0))); ComRender *pButterflyfish = static_cast<ComRender*>(_rootNode->getChildByTag(10008)->getComponent("CCArmature")); pButterflyfish->getNode()->runAction(MoveBy::create(10.0f, Point(-1000.0f, 0))); }
// on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !Layer::init() ) { return false; } m_fTime = 0.0f; m_bStart = false; m_bDead = false; m_fPercentage = 100.0f; m_fSpeed = 4.0f; m_fAttackDis = 120.0f; m_pGameScene = NULL; Node *pGameScene = cocostudio::SceneReader::getInstance()->createNodeWithSceneFile("FightScene.json"); m_pGameScene = pGameScene; this->addChild(pGameScene); ComRender *render = (ComRender*)(m_pGameScene->getChildByTag(10005)->getComponent("CCArmature")); Armature *pArmature = (Armature*)(render->getNode()); pArmature->getAnimation()->play("run"); m_bStart = true; LabelTTF* label = CCLabelTTF::create("End", "Marker Felt", 40); auto itemBack = MenuItemLabel::create(label, CC_CALLBACK_1(HelloWorld::menuCloseCallback, this)); itemBack->setColor(Color3B(255, 255, 255)); itemBack->setPosition(Point(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25)); Menu* menuBack =Menu::create(itemBack, NULL); menuBack->setPosition( Point::ZERO ); menuBack->setZOrder(4); this->addChild(menuBack); // CCMenuItemFont *itemBack = CCMenuItemFont::create("End", this, menu_selector(HelloWorld::menuCloseCallback)); // itemBack->setColor(ccc3(255, 255, 255)); // itemBack->setPosition(ccp(VisibleRect::rightBottom().x - 50, VisibleRect::rightBottom().y + 25)); // CCMenu *menuBack = CCMenu::create(itemBack, NULL); // menuBack->setPosition(CCPointZero); // menuBack->setZOrder(4); // // this->addChild(menuBack); scheduleUpdate(); return true; }
void ArmaturePlayAction::done() { do { Node *node = SceneReader::getInstance()->getNodeByTag(_tag); CC_BREAK_IF(node == nullptr); ComRender *pRender = (ComRender*)(node->getComponent(_ComName.c_str())); CC_BREAK_IF(pRender == nullptr); Armature *pAr = (Armature *)(pRender->getNode()); CC_BREAK_IF(pAr == nullptr); pAr->getAnimation()->play(_aniname.c_str()); } while (0); }
cocos2d::CCNode* RectangleCollisionTest::getNode(cocos2d::Node *pNode, std::string comName) { do { CC_BREAK_IF(pNode == NULL); Component *com = pNode->getComponent(comName.c_str()); CC_BREAK_IF(com == NULL); ComRender *render = dynamic_cast<ComRender*>(com); CC_BREAK_IF(render == NULL); return render->getNode(); } while (0); return NULL; }
ComRender* ComRender::create(void) { ComRender * ret = new (std::nothrow) ComRender(); if (ret != nullptr && ret->init()) { ret->autorelease(); } else { CC_SAFE_DELETE(ret); } return ret; }
cocos2d::Node* EffectComponentTest::createGameScene() { Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/EffectComponentTest/EffectComponentTest.json"); if (node == nullptr) { return nullptr; } _node = node; ComRender *render = static_cast<ComRender*>(_node->getChildByTag(10015)->getComponent("CCArmature")); 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)); return node; }
ComRender* ComRender::create(cocos2d::Node *node, const char *comName) { ComRender * ret = new (std::nothrow) ComRender(node, comName); if (ret != nullptr && ret->init()) { ret->autorelease(); } else { CC_SAFE_DELETE(ret); } return ret; }
void ArmatureActionState::removeAll() { do { Node *pNode = SceneReader::getInstance()->getNodeByTag(_tag); CC_BREAK_IF(pNode == nullptr); ComRender *pRender = (ComRender*)(pNode->getComponent(_comName.c_str())); CC_BREAK_IF(pRender == nullptr); Armature *pAr = (Armature *)(pRender->getNode()); CC_BREAK_IF(pAr == nullptr); TriggerMng::getInstance()->removeArmatureMovementCallBack(pAr, this, movementEvent_selector(ArmatureActionState::animationEvent)); } while (0); }
cocos2d::Node* ParticleComponentTest::createGameScene() { Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/ParticleComponentTest/ParticleComponentTest.json"); if (node == nullptr) { return nullptr; } ComRender* Particle = static_cast<ComRender*>(node->getChildByTag(10020)->getComponent("CCParticleSystemQuad")); ActionInterval* jump = JumpBy::create(5, Point(-500,0), 50, 4); FiniteTimeAction* action = Sequence::create( jump, jump->reverse(), nullptr); Particle->getNode()->runAction(action); return node; }
void HelloWorld::animationEvent(Armature *pArmature, MovementEventType movementType, const char *movementID) { ComRender *render = (ComRender*)(m_pGameScene->getChildByTag(10006)->getComponent("CCArmature")); Armature *pEnemy = (Armature*)(render->getNode()); if (movementType == COMPLETE) { pEnemy->getAnimation()->play("death"); pArmature->getAnimation()->setMovementEventCallFunc(NULL, NULL); m_bDead = true; } }
cocos2d::Node* ArmatureComponentTest::createGameScene() { Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/ArmatureComponentTest/ArmatureComponentTest.json"); if (node == nullptr) { return nullptr; } ComRender *pBlowFish = static_cast<ComRender*>(node->getChildByTag(10007)->getComponent("CCArmature")); pBlowFish->getNode()->runAction(CCMoveBy::create(10.0f, Point(-1000.0f, 0))); ComRender *pButterflyfish = static_cast<ComRender*>(node->getChildByTag(10008)->getComponent("CCArmature")); pButterflyfish->getNode()->runAction(CCMoveBy::create(10.0f, Point(-1000.0f, 0))); return node; }
void TmxMapComponentTest::defaultPlay() { ComRender *tmxMap = static_cast<ComRender*>(_rootNode->getChildByTag(10015)->getComponent("CCTMXTiledMap")); 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); ActionInterval *actionScaleToBack = CCScaleTo::create(2, 1.0f, 1.0f); ActionInterval *rotateToBack = CCRotateTo::create(2, 0); ActionInterval *actionToBack = CCSkewTo::create(2, 0, 0); tmxMap->getNode()->runAction(CCSequence::create(actionTo, actionToBack, nullptr)); tmxMap->getNode()->runAction(CCSequence::create(rotateTo, rotateToBack, nullptr)); tmxMap->getNode()->runAction(CCSequence::create(actionScaleTo, actionScaleToBack, nullptr)); }
cocos2d::Node* UIComponentTest::createGameScene() { Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/UIComponentTest/UIComponentTest.json"); if (node == nullptr) { return nullptr; } _node = node; ComRender *render = static_cast<ComRender*>(_node->getChildByTag(10025)->getComponent("GUIComponent")); Widget* widget = static_cast<cocos2d::ui::Widget*>(render->getNode()); Button* button = static_cast<Button*>(widget->getChildByName("Button_156")); button->addTouchEventListener(this, toucheventselector(UIComponentTest::touchEvent)); return node; }
void UIComponentTest::touchEvent(Ref *pSender, TouchEventType type) { switch (type) { case TOUCH_EVENT_BEGAN: { ComRender *pBlowFish = static_cast<ComRender*>(_node->getChildByTag(10010)->getComponent("CCArmature")); pBlowFish->getNode()->runAction(CCMoveBy::create(10.0f, Point(-1000.0f, 0))); ComRender *pButterflyfish = static_cast<ComRender*>(_node->getChildByTag(10011)->getComponent("CCArmature")); pButterflyfish->getNode()->runAction(CCMoveBy::create(10.0f, Point(-1000.0f, 0))); } break; default: break; } }
cocos2d::Node* TmxMapComponentTest::createGameScene() { Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/TmxMapComponentTest/TmxMapComponentTest.json"); if (node == nullptr) { return nullptr; } ComRender *tmxMap = static_cast<ComRender*>(node->getChildByTag(10015)->getComponent("CCTMXTiledMap")); 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->getNode()->runAction(Sequence::create(actionTo, actionToBack, nullptr)); tmxMap->getNode()->runAction(Sequence::create(rotateTo, rotateToBack, nullptr)); tmxMap->getNode()->runAction(Sequence::create(actionScaleTo, actionScaleToBack, nullptr)); return node; }
cocos2d::Node* SceneReader::createObject(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, cocos2d::Node* parent, AttachComponentType attachComponent) { const char *className = nullptr; stExpCocoNode *pNodeArray = cocoNode->GetChildArray(cocoLoader); std::string Key = pNodeArray[1].GetName(cocoLoader); if (Key == "classname") { className = pNodeArray[1].GetValue(cocoLoader); } if(strcmp(className, "CCNode") == 0) { Node* gb = nullptr; std::vector<Component*> _vecComs; ComRender *pRender = nullptr; int count = 0; std::string key = pNodeArray[13].GetName(cocoLoader); if (key == "components") { count = pNodeArray[13].GetChildNum(); } stExpCocoNode *pComponents = pNodeArray[13].GetChildArray(cocoLoader); SerData *data = new (std::nothrow) SerData(); for (int i = 0; i < count; ++i) { stExpCocoNode *subDict = pComponents[i].GetChildArray(cocoLoader); if (subDict == nullptr) { continue; } std::string key1 = subDict[1].GetName(cocoLoader); const char *comName = subDict[1].GetValue(cocoLoader); Component *pCom = nullptr; if (key1 == "classname" && comName != nullptr) { pCom = createComponent(comName); } CCLOG("classname = %s", comName); if (pCom != nullptr) { data->_rData = nullptr; data->_cocoNode = subDict; data->_cocoLoader = cocoLoader; if (pCom->serialize(data)) { ComRender *pTRender = dynamic_cast<ComRender*>(pCom); if (pTRender != nullptr) { pRender = pTRender; } else { _vecComs.push_back(pCom); } } else { CC_SAFE_RELEASE_NULL(pCom); } } if(_fnSelector != nullptr) { _fnSelector(pCom, (void*)(data)); } } CC_SAFE_DELETE(data); if (parent != nullptr) { if (pRender == nullptr || attachComponent == AttachComponentType::EMPTY_NODE) { gb = CCNode::create(); if (pRender != nullptr) { _vecComs.push_back(pRender); } } else { gb = pRender->getNode(); gb->retain(); pRender->setNode(nullptr); CC_SAFE_RELEASE_NULL(pRender); } parent->addChild(gb); } setPropertyFromJsonDict(cocoLoader, cocoNode, gb); for (std::vector<Component*>::iterator iter = _vecComs.begin(); iter != _vecComs.end(); ++iter) { gb->addComponent(*iter); } stExpCocoNode *pGameObjects = pNodeArray[12].GetChildArray(cocoLoader); if (pGameObjects != nullptr) { int length = pNodeArray[12].GetChildNum(); for (int i = 0; i < length; ++i) { createObject(cocoLoader, &pGameObjects[i], gb, attachComponent); } } return gb; } return nullptr; }
Node* SceneReader::createObject(const rapidjson::Value &dict, cocos2d::Node* parent, AttachComponentType attachComponent) { const char *className = DICTOOL->getStringValue_json(dict, "classname"); if(strcmp(className, "CCNode") == 0) { Node* gb = nullptr; if(nullptr == parent) { gb = Node::create(); } std::vector<Component*> vecComs; ComRender *render = nullptr; int count = DICTOOL->getArrayCount_json(dict, "components"); for (int i = 0; i < count; i++) { const rapidjson::Value &subDict = DICTOOL->getSubDictionary_json(dict, "components", i); if (!DICTOOL->checkObjectExist_json(subDict)) { break; } const char *comName = DICTOOL->getStringValue_json(subDict, "classname"); Component *com = this->createComponent(comName); CCLOG("classname = %s", comName); SerData *data = new (std::nothrow) SerData(); if (com != nullptr) { data->_rData = &subDict; data->_cocoNode = nullptr; data->_cocoLoader = nullptr; if (com->serialize(data)) { ComRender *tRender = dynamic_cast<ComRender*>(com); if (tRender == nullptr) { vecComs.push_back(com); } else { render = tRender; } } } CC_SAFE_DELETE(data); if(_fnSelector != nullptr) { _fnSelector(com, data); } } if (parent != nullptr) { if (render == nullptr || attachComponent == AttachComponentType::EMPTY_NODE) { gb = Node::create(); if (render != nullptr) { vecComs.push_back(render); } } else { gb = render->getNode(); gb->retain(); render->setNode(nullptr); } parent->addChild(gb); } setPropertyFromJsonDict(dict, gb); for (std::vector<Component*>::iterator iter = vecComs.begin(); iter != vecComs.end(); ++iter) { gb->addComponent(*iter); } int length = DICTOOL->getArrayCount_json(dict, "gameobjects"); for (int i = 0; i < length; ++i) { const rapidjson::Value &subDict = DICTOOL->getSubDictionary_json(dict, "gameobjects", i); if (!DICTOOL->checkObjectExist_json(subDict)) { break; } createObject(subDict, gb, attachComponent); } if(dict.HasMember("CanvasSize")) { const rapidjson::Value &canvasSizeDict = DICTOOL->getSubDictionary_json(dict, "CanvasSize"); if (DICTOOL->checkObjectExist_json(canvasSizeDict)) { int width = DICTOOL->getIntValue_json(canvasSizeDict, "_width"); int height = DICTOOL->getIntValue_json(canvasSizeDict, "_height"); gb->setContentSize(Size(width, height)); } } return gb; } return nullptr; }
Node* SceneReader::createObject(cs::JsonDictionary * inputFiles, Node* parenet, ISceneReaderListener* listener) { const char *className = inputFiles->getItemStringValue("classname"); if(strcmp(className, "CCNode") == 0) { Node* gb = NULL; if(NULL == parenet) { gb = Node::create(); } else { gb = Node::create(); parenet->addChild(gb); } setPropertyFromJsonDict(gb, inputFiles); int count = inputFiles->getArrayItemCount("components"); for (int i = 0; i < count; i++) { cs::JsonDictionary * subDict = inputFiles->getSubItemFromArray("components", i); if (!subDict) { CC_SAFE_DELETE(subDict); break; } const char *comName = subDict->getItemStringValue("classname"); const char *pComName = subDict->getItemStringValue("name"); cs::JsonDictionary *fileData = subDict->getSubDictionary("fileData"); std::string pPath; std::string pPlistFile; int nResType = 0; if (fileData != NULL) { const char *file = fileData->getItemStringValue("path"); nResType = fileData->getItemIntValue("resourceType", -1); const char *plistFile = fileData->getItemStringValue("plistFile"); if (file != NULL) { pPath.append(cocos2d::FileUtils::getInstance()->fullPathForFilename(file)); } if (plistFile != NULL) { pPlistFile.append(cocos2d::FileUtils::getInstance()->fullPathForFilename(plistFile)); } CC_SAFE_DELETE(fileData); } if (comName != NULL && strcmp(comName, "CCSprite") == 0) { cocos2d::Sprite *pSprite = NULL; if (nResType == 0) { if (pPath.find(".png") == pPath.npos) { continue; } pSprite = Sprite::create(pPath.c_str()); } else if (nResType == 1) { std::string pngFile = pPlistFile; std::string::size_type pos = pngFile.find(".plist"); if (pos == pPath.npos) { continue; } pngFile.replace(pos, pngFile.length(), ".png"); CCSpriteFrameCache::getInstance()->addSpriteFramesWithFile(pPlistFile.c_str(), pngFile.c_str()); pSprite = Sprite::createWithSpriteFrameName(pPath.c_str()); } else { continue; } ComRender *pRender = ComRender::create(pSprite, "CCSprite"); if (pComName != NULL) { pRender->setName(pComName); } gb->addComponent(pRender); } else if(comName != NULL && strcmp(comName, "CCTMXTiledMap") == 0) { cocos2d::TMXTiledMap *pTmx = NULL; if (nResType == 0) { if (pPath.find(".tmx") == pPath.npos) { continue; } pTmx = TMXTiledMap::create(pPath.c_str()); } else { continue; } ComRender *pRender = ComRender::create(pTmx, "CCTMXTiledMap"); if (pComName != NULL) { pRender->setName(pComName); } gb->addComponent(pRender); } else if(comName != NULL && strcmp(comName, "CCParticleSystemQuad") == 0) { std::string::size_type pos = pPath.find(".plist"); if (pos == pPath.npos) { continue; } cocos2d::ParticleSystemQuad *pParticle = NULL; if (nResType == 0) { pParticle = ParticleSystemQuad::create(pPath.c_str()); } else { CCLOG("unknown resourcetype on CCParticleSystemQuad!"); } pParticle->setPosition(0, 0); ComRender *pRender = ComRender::create(pParticle, "CCParticleSystemQuad"); if (pComName != NULL) { pRender->setName(pComName); } gb->addComponent(pRender); } else if(comName != NULL && strcmp(comName, "CCArmature") == 0) { if (nResType != 0) { continue; } std::string reDir = pPath; std::string file_path = ""; size_t pos = reDir.find_last_of('/'); if (pos != std::string::npos) { file_path = reDir.substr(0, pos+1); } unsigned long size = 0; const char *des = (char*)(cocos2d::FileUtils::getInstance()->getFileData(pPath.c_str(),"r" , &size)); cs::JsonDictionary *jsonDict = new cs::JsonDictionary(); jsonDict->initWithDescription(des); if(NULL == des || strcmp(des, "") == 0) { CCLOG("read json file[%s] error!\n", pPath.c_str()); } int childrenCount = DICTOOL->getArrayCount_json(jsonDict, "armature_data"); cs::JsonDictionary* subData = DICTOOL->getDictionaryFromArray_json(jsonDict, "armature_data", 0); const char *name = DICTOOL->getStringValue_json(subData, "name"); childrenCount = DICTOOL->getArrayCount_json(jsonDict, "config_file_path"); for (int i = 0; i < childrenCount; ++i) { const char* plist = DICTOOL->getStringValueFromArray_json(jsonDict, "config_file_path", i); std::string plistpath; plistpath += file_path; plistpath.append(plist); cocos2d::Dictionary *root = Dictionary::createWithContentsOfFile(plistpath.c_str()); Dictionary* metadata = DICTOOL->getSubDictionary(root, "metadata"); const char* textureFileName = DICTOOL->getStringValue(metadata, "textureFileName"); std::string textupath; textupath += file_path; textupath.append(textureFileName); cocos2d::extension::armature::ArmatureDataManager::getInstance()->addArmatureFileInfo(textupath.c_str(), plistpath.c_str(), pPath.c_str()); } cocos2d::extension::armature::Armature *pAr = cocos2d::extension::armature::Armature::create(name); ComRender *pRender = ComRender::create(pAr, "CCArmature"); if (pComName != NULL) { pRender->setName(pComName); } gb->addComponent(pRender); const char *actionName = subDict->getItemStringValue("selectedactionname"); if (actionName != NULL && pAr->getAnimation() != NULL) { pAr->getAnimation()->play(actionName); } CC_SAFE_DELETE(jsonDict); CC_SAFE_DELETE(subData); CC_SAFE_DELETE_ARRAY(des); } else if(comName != NULL && strcmp(comName, "CCComAudio") == 0) { ComAudio *pAudio = NULL; if (nResType == 0) { pAudio = ComAudio::create(); } else { continue; } pAudio->preloadEffect(pPath.c_str()); gb->addComponent(pAudio); } else if(comName != NULL && strcmp(comName, "CCComAttribute") == 0) { ComAttribute *pAttribute = NULL; if (nResType == 0) { pAttribute = ComAttribute::create(); unsigned long size = 0; const char* pData = 0; pData = (char*)(cocos2d::FileUtils::getInstance()->getFileData(pPath.c_str(), "r", &size)); if(pData != NULL && strcmp(pData, "") != 0) { pAttribute->getDict()->initWithDescription(pData); } } else { CCLOG("unknown resourcetype on CCComAttribute!"); continue; } gb->addComponent(pAttribute); } else if (comName != NULL && strcmp(comName, "CCBackgroundAudio") == 0) { ComAudio *pAudio = NULL; if (nResType == 0) { pAudio = ComAudio::create(); } else { continue; } pAudio->preloadBackgroundMusic(pPath.c_str()); pAudio->setFile(pPath.c_str()); bool bLoop = subDict->getItemIntValue("loop", 0); pAudio->setLoop(bLoop); gb->addComponent(pAudio); pAudio->playBackgroundMusic(pPath.c_str(), bLoop); } else if(comName != NULL && strcmp(comName, "GUIComponent") == 0) { cocos2d::extension::UILayer *pLayer = cocos2d::extension::UILayer::create(); pLayer->scheduleUpdate(); UIWidget* widget = cocos2d::extension::UIHelper::instance()->createWidgetFromJsonFile(pPath.c_str(), listener); pLayer->addWidget(widget); ComRender *pRender = ComRender::create(pLayer, "GUIComponent"); if (pComName != NULL) { pRender->setName(pComName); } gb->addComponent(pRender); } CC_SAFE_DELETE(subDict); } for (int i = 0; i < inputFiles->getArrayItemCount("gameobjects"); i++) { cs::JsonDictionary * subDict = inputFiles->getSubItemFromArray("gameobjects", i); if (!subDict) { break; } createObject(subDict, gb,listener); CC_SAFE_DELETE(subDict); } if (listener) listener->OnNodeLoaded(gb); return gb; } return NULL; }
void HelloWorld::update(float delta) { if(m_bStart) { ComRender *pHeroRender = (ComRender*)(m_pGameScene->getChildByTag(10005)->getComponent("CCArmature")); Armature *pHero = (Armature*)(pHeroRender->getNode()); pHero->getParent()->setPositionX(pHero->getParent()->getPositionX() + m_fSpeed); ComRender *pEnemyRender = (ComRender*)(m_pGameScene->getChildByTag(10006)->getComponent("CCArmature")); Armature *pEnemy = (Armature*)(pEnemyRender->getNode()); /* for 3.0 */ float distance = Point(pHero->getParent()->getPositionX(), 0).getDistance(Point(pEnemy->getParent()->getPositionX(), 0)); if (distance < m_fAttackDis) { pHero->getAnimation()->play("attack"); pHero->getAnimation()->setMovementEventCallFunc(this, movementEvent_selector(HelloWorld::animationEvent)); m_bStart = false; } // before /* if(ccpDistance(ccp(pHero->getParent()->getPositionX(), 0), ccp(pEnemy->getParent()->getPositionX(), 0)) < m_fAttackDis) { pHero->getAnimation()->play("attack"); pHero->getAnimation()->setMovementEventCallFunc(this, movementEvent_selector(HelloWorld::animationEvent)); m_bStart = false; } */ /**/ } if(m_bDead) { ComRender *pUIRender = static_cast<ComRender*>(m_pGameScene->getChildByTag(10007)->getComponent("GUIComponent")); /* for 3.0 */ Node* pUILayer = static_cast<Node*>(pUIRender->getNode()); Layout* root = static_cast<Layout*>(pUILayer->getChildren().at(2)); LoadingBar *pHPLoadingBar = static_cast<LoadingBar*>(Helper::seekWidgetByName(root, "hp02_LoadingBar")); LoadingBar *pMPLoadingBar = static_cast<LoadingBar*>(Helper::seekWidgetByName(root, "mp02_LoadingBar")); // before /* cocos2d::ui::TouchGroup *pUILayer = static_cast<cocos2d::ui::TouchGroup*>(pUIRender->getNode()); cocos2d::ui::LoadingBar *pHPLoadingBar = static_cast<cocos2d::ui::LoadingBar*>(pUILayer->getWidgetByName("hp02_LoadingBar")); cocos2d::ui::LoadingBar *pMPLoadingBar = static_cast<cocos2d::ui::LoadingBar*>(pUILayer->getWidgetByName("mp02_LoadingBar")); */ /**/ pHPLoadingBar->setPercent(m_fPercentage); pMPLoadingBar->setPercent(m_fPercentage); m_fPercentage -= 2.0f; if (m_fPercentage < 0.0f) { unscheduleUpdate(); } } }
void EffectComponentTest::defaultPlay() { ComRender *render = static_cast<ComRender*>(_rootNode->getChildByTag(10015)->getComponent("CCArmature")); 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)); }
Node* SceneReader::createObject(const rapidjson::Value &dict, cocos2d::Node* parent, AttachComponentType attachComponent) { const char *className = DICTOOL->getStringValue_json(dict, "classname"); if(strcmp(className, "CCNode") == 0) { Node* gb = nullptr; if(nullptr == parent) { gb = Node::create(); } std::vector<Component*> vecComs; ComRender *render = nullptr; int count = DICTOOL->getArrayCount_json(dict, "components"); for (int i = 0; i < count; i++) { const rapidjson::Value &subDict = DICTOOL->getSubDictionary_json(dict, "components", i); if (!DICTOOL->checkObjectExist_json(subDict)) { break; } const char *comName = DICTOOL->getStringValue_json(subDict, "classname"); Component *com = ObjectFactory::getInstance()->createComponent(comName); if (com != nullptr) { if (com->serialize((void*)(&subDict))) { ComRender *tRender = dynamic_cast<ComRender*>(com); if (tRender == nullptr) { vecComs.push_back(com); } else { render = tRender; } } } if(_fnSelector != nullptr) { _fnSelector(com, (void*)(&subDict)); } } if (parent != nullptr) { if (render == nullptr || attachComponent == AttachComponentType::EMPTY_NODE) { gb = Node::create(); if (render != nullptr) { vecComs.push_back(render); } } else { gb = render->getNode(); gb->retain(); render->setNode(nullptr); } parent->addChild(gb); } setPropertyFromJsonDict(dict, gb); for (std::vector<Component*>::iterator iter = vecComs.begin(); iter != vecComs.end(); ++iter) { gb->addComponent(*iter); } int length = DICTOOL->getArrayCount_json(dict, "gameobjects"); for (int i = 0; i < length; ++i) { const rapidjson::Value &subDict = DICTOOL->getSubDictionary_json(dict, "gameobjects", i); if (!DICTOOL->checkObjectExist_json(subDict)) { break; } createObject(subDict, gb, attachComponent); } return gb; } return nullptr; }