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)); }
void CHorseRunning::benginRunning() { Size visibleSize = Director::getInstance()->getVisibleSize(); //Point origin = Director::getInstance()->getVisibleOrigin(); ArmatureDataManager::getInstance()->addArmatureFileInfo("putongma001.ExportJson"); m_pArmature = Armature::create("putongma001"); m_pArmature->getAnimation()->play("Animation1"); m_pArmature->setScale(0.5); m_pArmature->getAnimation()->setSpeedScale(1); m_pArmature->setZOrder(1000 - 345); m_pArmature->setPosition(Point(visibleSize.width/2 ,345)); addChild(m_pArmature); m_nType = 1; for (int i = 1; i<10; i++) { ArmatureDataManager::getInstance()->addArmatureFileInfo(StringUtils::format("guanzhong_00%d.ExportJson",i)); cocostudio::Armature* armature = Armature::create(StringUtils::format("guanzhong_00%d",i)); armature->getAnimation()->play("Animation1"); // armature->setScale(0.5); armature->getAnimation()->setSpeedScale(1); armature->setPosition(Point(visibleSize.width*i/18+ visibleSize.width/6, visibleSize.height*3/4)); addChild(armature); } for(int i = 10;i<21;i++) { if(i==17) { ArmatureDataManager::getInstance()->addArmatureFileInfo("guanzhong_17.ExportJson"); cocostudio::Armature* armature = Armature::create("guanzhong_17"); armature->getAnimation()->play("Animation1"); // armature->setScale(0.5); armature->getAnimation()->setSpeedScale(1); armature->setPosition(Point(visibleSize.width*(i-9)/18 + visibleSize.width/6, visibleSize.height*3/4 + visibleSize.width/18)); addChild(armature); } else { ArmatureDataManager::getInstance()->addArmatureFileInfo(StringUtils::format("guanzhong_0%d.ExportJson",i)); cocostudio::Armature* armature = Armature::create(StringUtils::format("guanzhong_0%d",i)); armature->getAnimation()->play("Animation1"); // armature->setScale(0.5); armature->getAnimation()->setSpeedScale(1); armature->setPosition(Point(visibleSize.width*(i-9)/18+ visibleSize.width/6, visibleSize.height*3/4 + visibleSize.width/18)); addChild(armature); } } ArmatureDataManager::getInstance()->addArmatureFileInfo("sheyingshi001.ExportJson"); m_pDirector = Armature::create("sheyingshi001"); m_pDirector->getAnimation()->play("Animation1"); m_pDirector->getAnimation()->setSpeedScale(1); m_pDirector->setPosition(Point(visibleSize.width/2 + 100,0)); m_pDirector->setZOrder(1000); addChild(m_pDirector); ArmatureDataManager::getInstance()->addArmatureFileInfo("baozouzu_001.ExportJson"); Armature* armatureAi = Armature::create("baozouzu_001"); armatureAi->getAnimation()->play("Animation1"); armatureAi->getAnimation()->setSpeedScale(1); armatureAi->setScale(0.5); armatureAi->setPosition(Point(visibleSize.width/2,255)); armatureAi->setZOrder(1000 - 255); addChild(armatureAi); m_VecArmatureAi.pushBack(armatureAi); ArmatureDataManager::getInstance()->addArmatureFileInfo("baozouzu_002.ExportJson"); Armature* armatureAi2 = Armature::create("baozouzu_002"); armatureAi2->getAnimation()->play("Animation1"); armatureAi2->getAnimation()->setSpeedScale(1); armatureAi2->setScale(0.5); armatureAi2->setPosition(Point(visibleSize.width*3/4,185)); armatureAi2->setZOrder(1000 - 185); addChild(armatureAi2); m_VecArmatureAi.pushBack(armatureAi2); ArmatureDataManager::getInstance()->addArmatureFileInfo("baozouzu_002.ExportJson"); Armature* armatureAi3 = Armature::create("baozouzu_002"); armatureAi3->getAnimation()->play("Animation1"); armatureAi3->getAnimation()->setSpeedScale(1); armatureAi3->setScale(0.5); armatureAi3->setPosition(Point(visibleSize.width*3/4,125)); armatureAi3->setZOrder(1000 - 125); addChild(armatureAi3); m_VecArmatureAi.pushBack(armatureAi3); //m_pDirector->getAnimation()->setFrameEventCallFunc(this,frameEvent_selector(CHorseRunning::onFrameEvent)); m_pArmature->runAction(Sequence::create(RotateBy::create(2,-360), NULL)); }
bool FiledScene::init(){ if (!Layer::init()) return false; _isGameOver = false; auto visibleSize = Director::getInstance()->getVisibleSize(); _screenWidth = visibleSize.width; _screenHeight = visibleSize.height; _tileMap = TMXTiledMap::create("field_map.tmx"); _tileMap->setAnchorPoint(Vec2::ANCHOR_MIDDLE); _tileMap->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2)); // ②获取障碍层,并设置障碍层为不可见 _collidable = _tileMap->getLayer("collidable"); _collidable->setVisible(false); /********③初始化读取地图所有网格,并确定网格对象是否是障碍物,将信息保存到网格二维数组**************/ for (int i = 0; i < _tileMap->getMapSize().width; i++) { // 内部网格集合([x,0]-[x-20]),存储网格 Vector<Grid*> inner; for (int j = 0; j < _tileMap->getMapSize().height; j++) { // 设置网格对象的x轴和y轴以及是否可通过变量值 Grid *o = Grid::create(i, j); // 将网格加入到集合 inner.pushBack(o); } // 将内部集合加入到网格集合 _gridVector.push_back(inner); } // 循环保存根据每个网格的x轴和y轴查找对应的地图的GID,判断是否可通过 for (int i = 0; i < _gridVector.size(); i++) { Vector<Grid*> inner = _gridVector.at(i); // 循环内部网格集合 for (int j = 0; j < inner.size(); j++) { // 获取每一个网格对象 Grid *grid = inner.at(j); // 获取每一个网格对象对应的的坐标 Vec2 tileCoord = Vec2(grid->getX(), grid->getY()); // 使用TMXLayer类的tileGIDAt函数获取TileMap坐标系里的“全局唯一标识”GID int tileGid = _collidable->getTileGIDAt(tileCoord); if (tileGid) { // 使用GID来查找指定tile的属性,返回一个Value Value properties = _tileMap->getPropertiesForGID(tileGid); // 返回的Value实际是一个ValueMap ValueMap map = properties.asValueMap(); // 查找ValueMap,判断是否有”可碰撞的“物体,如果有,设置网格对象的isPass变量为false std::string value = map.at("collidable").asString(); if (value.compare("true") == 0) { grid->setPass(false); } } } } // 人物出场特效 auto effects_player_out = Sprite::create("effects/effects_player_out/effects_player_out_11.png"); effects_player_out->setPosition(Vec2(visibleSize.width*0.3,visibleSize.height*0.3)); this->addChild(effects_player_out, 1); auto player_out_animate = getAnimateByName("effects/effects_player_out/effects_player_out_", 0.1f, 11); auto delay1 = DelayTime::create(1.5f); auto fadeOut = FadeOut::create(0.2f); auto sequence = Sequence::create(delay1, player_out_animate, fadeOut, nullptr); effects_player_out->runAction(sequence); _player = SpriteBase::create("player/player_sword/player_sword_stand.png"); this->addChild(_player, 1); _player->setPosition(Vec2(visibleSize.width*0.3, visibleSize.height*0.3)); this->addChild(_tileMap,0); _player->setFlippedX(true); XmlTools::readPlayerData(_player); /// 传送门 ArmatureDataManager::getInstance()->addArmatureFileInfo("/buildings/gate/AnimationStart0.png", "/buildings/gate/AnimationStart0.plist", "/buildings/gate/AnimationStart.ExportJson"); Armature *armature = Armature::create("AnimationStart"); armature->getAnimation()->play("Start"); this->addChild(armature); armature->setScale(0.3); armature->setPosition(Vec2(visibleSize.width*0.9, visibleSize.height*0.7)); auto gate_effect = ParticleSystemQuad::create("effects/gate_effect.plist"); this->addChild(gate_effect); gate_effect->setScale(0.3); gate_effect->setPosition(Vec2(visibleSize.width*0.9, visibleSize.height*0.75)); gate_effect->setPositionType(kCCPositionTypeRelative); // 结束战斗按钮 auto end_fight_button = Button::create("ui/end_fight.png"); end_fight_button->setPosition(Vec2(visibleSize.width*0.95, visibleSize.height*0.97)); end_fight_button->setScale(0.5f); this->addChild(end_fight_button, 0); //结束战斗对话框 auto end_fight_dialog_bg = Sprite::create("ui/end_fight_dialog_bg.png"); end_fight_dialog_bg->setAnchorPoint(Vec2::ANCHOR_MIDDLE); end_fight_dialog_bg->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2)); this->addChild(end_fight_dialog_bg, 3); // 确定结束战斗按钮 auto end_fight_sub_button = Button::create("ui/end_fight_sub_button.png"); end_fight_dialog_bg->addChild(end_fight_sub_button); end_fight_sub_button->setAnchorPoint(Vec2::ZERO); end_fight_sub_button->setPosition(Vec2(20, 30)); end_fight_sub_button->addTouchEventListener([=](Ref* pSender, Widget::TouchEventType type){ XmlTools::writePlayerData(_player); auto transition = TransitionSplitCols::create(2, Game::createScene()); Director::getInstance()->pushScene(transition); }); // 取消结束战斗按钮 auto end_fight_cancel_button = Button::create("ui/end_fight_cancel_button.png"); end_fight_dialog_bg->addChild(end_fight_cancel_button); end_fight_cancel_button->setAnchorPoint(Vec2::ZERO); end_fight_cancel_button->setPosition(Vec2(140, 30)); end_fight_cancel_button->addTouchEventListener([=](Ref* pSender, Widget::TouchEventType type){ end_fight_dialog_bg->setVisible(false); }); end_fight_dialog_bg->setVisible(false); end_fight_button->addTouchEventListener([=](Ref* pSender, Widget::TouchEventType type){ if (type == Widget::TouchEventType::ENDED){ end_fight_dialog_bg->setVisible(true); } }); // ⑤创建事件监听器 auto gameListener = EventListenerTouchOneByOne::create(); // 响应触摸事件函数 gameListener->onTouchBegan = [](Touch* touch, Event* event){return true; }; gameListener->onTouchEnded = [=](Touch *touch, Event *event){ // OpenGL坐标 Vec2 touchLocation = touch->getLocation(); // 将触摸点坐标转换成相对的Node坐标 Vec2 nodeLocation = this->convertToNodeSpace(touchLocation); // 玩家镜像反转 if (_player->getPosition().x > nodeLocation.x) { if (_player->isFlippedX() == true){ _player->setFlippedX(false); } } else{ if (_player->isFlippedX() == false) _player->setFlippedX(true); } // 用玩家位置作为起点,触摸点作为终点,转换为网格坐标,在地图上查找最佳到达路径 Vec2 from = tileCoordForPosition(_player->getPosition()); Vec2 to = tileCoordForPosition(nodeLocation); // 如果终点是不可通过(即有障碍物)的位置,则直接return int tileGid = _collidable->getTileGIDAt(to); if (tileGid) { // 使用GID来查找指定tile的属性,返回一个Value Value properties = _tileMap->getPropertiesForGID(tileGid); // 返回的Value实际是一个ValueMap ValueMap map = properties.asValueMap(); // 查找ValueMap,判断是否有”可碰撞的“物体,如果有,直接返回 std::string value = map.at("collidable").asString(); if (value.compare("true") == 0) { return; } } /**************玩家精灵移动到指定位置************************/ // 在玩家精灵移动过程中,如果用户在此触摸屏幕移动玩家时,如果精灵没有运行动作,直接执行移动动作 if (_player->getNumberOfRunningActions() == 0) { this->playerMover(nodeLocation); } else { //如果精灵正在运行动作,先停止精灵动作和层动作,再执行移动动作 _player->stopAllActions(); this->stopAllActions(); this->playerMover(nodeLocation); } // 接触传送门, 如果boss被杀死, 则传送回主场景. if (_player->getBoundingBox().intersectsRect(armature->getBoundingBox())){ if (monster_1->isVisible()==false){ _player->setExp(_player->getExp() + 200); _player->setGold(_player->getGold() + 1000); XmlTools::writePlayerData(_player); const string player_task = FileUtils::getInstance()->fullPathForFilename("data/kill_count.xml"); ssize_t player_taskFile_size; char* pPlayerTaskContent = (char*)FileUtils::getInstance()->getFileData(player_task, "r", &player_taskFile_size); TiXmlDocument* player_task_el = new TiXmlDocument(); player_task_el->Parse(pPlayerTaskContent, 0, TIXML_ENCODING_UTF8); TiXmlElement* rootElement = player_task_el->RootElement();//Root TiXmlElement* player_kill_count_1 = rootElement->FirstChildElement(); string accept = player_kill_count_1->GetText(); TiXmlElement* player_kill_count_2 = player_kill_count_1->NextSiblingElement(); stringstream ss; string kill_count = player_kill_count_2->GetText(); int kill_count_int; ss << kill_count; ss >> kill_count_int; if (accept=="true"){ kill_count_int += 1; player_kill_count_2->Clear(); string kill_count_str; stringstream ss; ss << kill_count_int; ss >> kill_count_str; TiXmlText* kill_count_text = new TiXmlText(kill_count_str.c_str()); player_kill_count_2->LinkEndChild(kill_count_text); player_task_el->SaveFile(player_task.c_str()); } auto transform_to = TransitionSplitCols::create(2.0f, Game::createScene()); Director::getInstance()->pushScene(transform_to); }
/** * Build and returns a new Armature instance. * @example * <listing> * var armature:Armature = factory.buildArmature('dragon'); * </listing> * @param armatureName The name of this Armature instance. * @param The name of this animation * @param The name of this SkeletonData. * @param The name of this textureAtlas. * @param The name of this skin. * @return A Armature instance. */ Armature* BaseFactory::buildArmature(const String &armatureName, const String &animationName, const String &skeletonName, const String &textureAtlasName, const String &skinName) { ArmatureData* armatureData = 0; SkeletonData *data = 0; if(!skeletonName.empty()) { std::map<String , SkeletonData*>::iterator iter = _dataDic.find(skeletonName); if(iter != _dataDic.end()) { data = iter->second; armatureData = data->getArmatureData(armatureName); } } //else //{ // for(skeletonName in _dataDic) // { // data = _dataDic[skeletonName]; // armatureData = data->getArmatureData(armatureName); // if(armatureData) // { // break; // } // } //} if(!armatureData) { return nullptr; } _currentDataName = skeletonName; _currentTextureAtlasName = textureAtlasName.empty() ? skeletonName : textureAtlasName; Armature* armature = generateArmature(); armature->name = armatureName; Bone* bone; for(size_t i = 0 ; i < armatureData->boneDataList.size() ; i ++) { BoneData* boneData = armatureData->boneDataList[i]; bone = new Bone(); bone->name = boneData->name; bone->fixedRotation = boneData->fixedRotation; bone->scaleMode = boneData->scaleMode; bone->origin = boneData->transform; if(armatureData->getBoneData(boneData->parent)) { armature->addBone(bone, boneData->parent); } else { armature->addBone(bone); } } ArmatureData* animationArmatureData = 0; SkinData *skinDataCopy = 0; if(!animationName.empty() && animationName != armatureName) { //ArmatureData* animationArmatureData = data->getArmatureData(animationName); // Get the default animation //if(!animationArmatureData) //{ // for (skeletonName in _dataDic) // { // data = _dataDic[skeletonName]; // animationArmatureData = data->getArmatureData(animationName); // if(animationArmatureData) // { // break; // } // } //} ArmatureData* armatureDataCopy = data->getArmatureData(animationName); if(armatureDataCopy) { skinDataCopy = armatureDataCopy->getSkinData(""); } } if(animationArmatureData) { armature->getAnimation()->setAnimationDataList(animationArmatureData->animationDataList); } else { armature->getAnimation()->setAnimationDataList(armatureData->animationDataList); } SkinData* skinData = armatureData->getSkinData(skinName); if(!skinData) { return nullptr; //throw new ArgumentError(); } Slot* slot; DisplayData* displayData; Armature* childArmature; size_t i; //var helpArray:Array = []; for(size_t j = 0 ; j < skinData->slotDataList.size() ; j ++) { SlotData* slotData = skinData->slotDataList[j]; bone = armature->getBone(slotData->parent); if(!bone) { continue; } slot = generateSlot(); slot->name = slotData->name; slot->setBlendMode(slotData->blendMode); slot->_originZOrder = slotData->zOrder; slot->_dislayDataList = slotData->displayDataList; std::vector<Object*> helpArray; i = slotData->displayDataList.size(); helpArray.resize(i); while(i --) { displayData = slotData->displayDataList[i]; if(displayData->type == DisplayData::ARMATURE) { DisplayData* displayDataCopy = 0; if(skinDataCopy) { SlotData* slotDataCopy = skinDataCopy->getSlotData(slotData->name); if(slotDataCopy) { displayDataCopy = slotDataCopy->displayDataList[i]; } } else { displayDataCopy = 0; } childArmature = buildArmature(displayData->name, displayDataCopy?displayDataCopy->name:"", _currentDataName, _currentTextureAtlasName); if(childArmature) { helpArray[i] = childArmature; } //fix by Wayne Dimart: // break; we don't use break here, or will crach the program due to incomplete helpArray. continue; } else { helpArray[i] = generateDisplay(getTextureAtlas(_currentTextureAtlasName), displayData->name, displayData->pivot.x, displayData->pivot.y); } } slot->setDisplayList(helpArray); slot->changeDisplay(0); bone->addChild(slot); } // i = armature->_boneList.size(); while(i --) { armature->_boneList[i]->update(); } i = armature->_slotList.size(); while(i --) { slot = armature->_slotList[i]; slot->update(); } armature->updateSlotsZOrder(); return armature; }
// on "init" you need to initialize your instance bool HelloWorld::init() { bool bRet = false; do { ////////////////////////////////////////////////////////////////////////// // super init first ////////////////////////////////////////////////////////////////////////// CC_BREAK_IF(! CCLayerColor::initWithColor(ccc4(200, 200, 200, 255))); // CC_BREAK_IF(! CCLayerColor::initWithColor(ccc4(0, 0, 0, 255))); CCSize size = CCDirector::sharedDirector()->getWinSize(); weaponIndex = 0; BatchNodeManager::sharedBatchNodeManager()->initWithLayer(this, "TEST_ARMATURE"); ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("Zombie_f/Zombie", "", "zombie.png", "zombie.plist", "zombie.xml"); ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("Knight_f/Knight", "", "knight.png", "knight.plist", "knight.xml"); ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("cyborg", "", "cyborg.png", "cyborg.plist", "cyborg.xml"); ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("Zombie_ladder", "", "zombie_ladder.png", "zombie_ladder.plist", "zombie_ladder.xml"); ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("bird", "", "bird.png", "bird.plist", "bird.xml"); ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("weapon", "", "weapon.png", "weapon.plist", "weapon.xml"); armatures = new CCArray(); Armature *armature = NULL; //! use BATCHNODE_VERTEXZ you can change display in different batchnode BatchNodeManager::sharedBatchNodeManager()->getBatchNode("weapon.png")->setRenderType(BATCHNODE_VERTEXZ); armature = Armature::create("Knight_f/Knight"); armature->getAnimation()->play("run"); armature->setPosition(size.width/2 + 50, size.height/2); armatures->addObject(armature); armature = Armature::create("cyborg"); armature->getAnimation()->play("run"); armature->setPosition(size.width/2 + 130, size.height/2); armature->getAnimation()->MovementEventSignal.connect(this, &HelloWorld::onMovementEvent); armature->setZOrder(2); armatures->addObject(armature); // armature = Armature::create("Zombie_f/Zombie"); armature->getAnimation()->play("run"); armature->setPosition(size.width/2 + 100, size.height/2); armature->setZOrder(1); armatures->addObject(armature); // armature = Armature::create("Knight_f/Knight"); // armature->getAnimation()->play("run"); // armature->setPosition(size.width/2 - 150, size.height/2); // // SpriteDisplayData *param = SpriteDisplayData::create(); // param->setParam("weapon_f-sword2.png"); // // armature->getBone("weapon")->addDisplay(param, 0); // armature->setRenderType(BATCHNODE_VERTEXZ); // armatures->addObject(armature); // armature = Armature::create("Zombie_ladder"); armature->getAnimation()->play("anim_placeladder", 0, 50, 1, TWEEN_EASING_MAX); armature->getAnimation()->setAnimationScale(3); armature->setPosition(size.width/2 - 230, size.height/2 -100); armatures->addObject(armature); armature = Armature::create("bird"); armature->getAnimation()->play("changeColor"); armature->setPosition(size.width/2 - 230, size.height/2 + 100); armatures->addObject(armature); // for (int i = 0; i<600; i++) // { // Armature *armature = Armature::create("Knight_f/Knight"); // armature->getAnimation()->play("run"); // armature->setPosition(30 + (i%20)*(size.width/21), 30 + (i/20)*20); // armatures->addObject(armature); // } scheduleUpdate(); bRet = true; } while (0); return bRet; }
void EventBoard::playAni() { Armature *armature = (Armature*)_UINode->getChildByTag(888); armature->setVisible(true); armature->getAnimation()->playWithIndex(0, -1, 0);//from the first frame, no loop }
Armature* BaseFactory::buildArmature(const std::string &armatureName, const std::string &skinName, const std::string &animationName, const std::string &dragonBonesName, const std::string &textureAtlasName) const { DragonBonesData *dragonBonesData = nullptr; ArmatureData *armatureData = nullptr; ArmatureData *animationArmatureData = nullptr; SkinData *skinData = nullptr; SkinData *skinDataCopy = nullptr; if (!dragonBonesName.empty()) { auto iterator = _dragonBonesDataMap.find(dragonBonesName); if (iterator != _dragonBonesDataMap.end()) { dragonBonesData = iterator->second; armatureData = dragonBonesData->getArmatureData(armatureName); _currentDragonBonesDataName = dragonBonesName; _currentTextureAtlasName = textureAtlasName.empty() ? _currentDragonBonesDataName : textureAtlasName; } } if (!armatureData) { AutoSearchType searchType = (dragonBonesName.empty() ? AutoSearchType::AST_ALL : (autoSearchDragonBonesData ? AutoSearchType::AST_AUTO : AutoSearchType::AST_NONE)); if (searchType != AutoSearchType::AST_NONE) { for (auto iterator = _dragonBonesDataMap.begin(); iterator != _dragonBonesDataMap.end(); ++iterator) { dragonBonesData = iterator->second; if (searchType == AutoSearchType::AST_ALL || dragonBonesData->autoSearch) { armatureData = dragonBonesData->getArmatureData(armatureName); if (armatureData) { _currentDragonBonesDataName = iterator->first; _currentTextureAtlasName = _currentDragonBonesDataName; break; } } } } } if (!armatureData) { return nullptr; } if (!animationName.empty() && animationName != armatureName) { animationArmatureData = dragonBonesData->getArmatureData(animationName); if (!animationArmatureData) { for (auto iterator = _dragonBonesDataMap.begin(); iterator != _dragonBonesDataMap.end(); ++iterator) { dragonBonesData = iterator->second; animationArmatureData = dragonBonesData->getArmatureData(animationName); if (animationArmatureData) { break; } } } if (animationArmatureData) { skinDataCopy = animationArmatureData->getSkinData(""); } } skinData = armatureData->getSkinData(skinName); Armature *armature = generateArmature(armatureData); armature->name = armatureName; if (animationArmatureData) { armature->getAnimation()->setAnimationDataList(animationArmatureData->animationDataList); } else { armature->getAnimation()->setAnimationDataList(armatureData->animationDataList); } // buildBones(armature, armatureData); // if (skinData) { buildSlots(armature, armatureData, skinData, skinDataCopy); } // update armature pose armature->getAnimation()->play(); armature->advanceTime(0); armature->getAnimation()->stop(); return armature; }
// on "init" you need to initialize your instance bool HelloWorld::init() { bool bRet = false; do { ////////////////////////////////////////////////////////////////////////// // super init first ////////////////////////////////////////////////////////////////////////// CC_BREAK_IF(! CCLayerColor::initWithColor(ccc4(200, 200, 200, 255))); // CC_BREAK_IF(! CCLayerColor::initWithColor(ccc4(0, 0, 0, 255))); CCSize size = CCDirector::sharedDirector()->getWinSize(); weaponIndex = 0; BatchNodeManager::sharedBatchNodeManager()->initWithLayer(this, "TEST_ARMATURE"); ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("Zombie_f/Zombie", "", "zombie.png", "zombie.plist", "zombie.xml"); ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("Knight_f/Knight", "", "knight.png", "knight.plist", "knight.xml"); ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("cyborg", "", "cyborg.png", "cyborg.plist", "cyborg.xml"); // if the png, plist, xml is same, you can use param _useExistFileInfo ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armInside", "cyborg", "", "", ""); ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("armOutside", "cyborg", "", "", ""); ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("circle_in_circle_stage3", "", "loading.png", "loading.plist", "loading.xml"); ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("Cattail", "", "Cattail.png", "Cattail.plist", "Cattail.xml"); ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("Zombie_ladder", "", "zombie_ladder.png", "zombie_ladder.plist", "zombie_ladder.xml"); ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("Zombie_ladder", "", "zombie_ladder.png", "zombie_ladder.plist", "zombie_ladder.xml"); ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("bird", "", "bird.png", "bird.plist", "bird.xml"); ArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("weapon", "", "weapon.png", "weapon.plist", "weapon.xml"); armatures = new CCArray(); Armature *armature = NULL; //! use BATCHNODE_VERTEXZ you can change display in different batchnode BatchNodeManager::sharedBatchNodeManager()->getBatchNode("knight.png")->setRenderType(BATCHNODE_VERTEXZ); BatchNodeManager::sharedBatchNodeManager()->getBatchNode("cyborg.png")->setRenderType(BATCHNODE_VERTEXZ); BatchNodeManager::sharedBatchNodeManager()->getBatchNode("zombie.png")->setRenderType(BATCHNODE_VERTEXZ); armature = Armature::create("cyborg"); armature->getAnimation()->play("run"); armature->getDisplay()->setPosition(ccp(size.width/2 + 130, size.height/2)); armature->setZOrder(2); armature->setAnimationCallback(this); armatures->addObject(armature); armature = Armature::create("Zombie_f/Zombie"); armature->getAnimation()->play("run"); armature->getDisplay()->setPosition(ccp(size.width/2 + 100, size.height/2)); armature->setZOrder(1); armatures->addObject(armature); armature = Armature::create("Knight_f/Knight"); armature->getAnimation()->play("run"); armature->getDisplay()->setPosition(ccp(size.width/2 + 50, size.height/2)); armatures->addObject(armature); armature = Armature::create("Knight_f/Knight"); armature->getAnimation()->play("run"); armature->getDisplay()->setPosition(ccp(size.width/2 - 150, size.height/2)); armature->getBone("weapon")->addSpriteDisplay("weapon_f-sword2.png", "weapon.png", 0); armatures->addObject(armature); // armature = Armature::create("circle_in_circle_stage3"); // armature->getAnimation()->play("loading"); // armature->getDisplay()->setPosition(ccp(size.width/2, size.height/2)); // armatures->addObject(armature); armature = Armature::create("Cattail"); armature->getAnimation()->play("anim_shooting"); armature->getDisplay()->setPosition(ccp(size.width/2 + 50, size.height/2 - 100)); armatures->addObject(armature); armature = Armature::create("Zombie_ladder"); armature->getAnimation()->play("anim_placeladder", 0, 50, 1, TWEEN_EASING_MAX); armature->getAnimation()->setAnimationScale(3); armature->getDisplay()->setPosition(ccp(size.width/2 - 230, size.height/2 -100)); armatures->addObject(armature); armature = Armature::create("bird"); armature->getAnimation()->play("changeColor"); armature->getDisplay()->setPosition(ccp(size.width/2 - 230, size.height/2 + 100)); armatures->addObject(armature); // for (int i = 0; i<500; i++) // { // Armature *armature = Armature::create("Knight_f/Knight"); // armature->getAnimation()->play("run"); // armature->getDisplay()->setPosition(ccp(30 + (i%20)*(size.width/21), 30 + (i/20)*20)); // armatures->addObject(armature); // } scheduleUpdate(); bRet = true; } while (0); return bRet; }
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(); } } }