void CHeroEvolveEffectLayer::initEffect() { //加载资源-两个动画资源 if(m_pEffectBase!=nullptr) { m_pEffectBase->removeFromParentAndCleanup(true); } m_pEffectBase = CCArmature::create("evol2"); m_pEffectBase->setPosition(ccp(DESIGN_WIDTH/2, VIRTUAL_FIXED_HEIGHT/2)); m_pUI->addChild(m_pEffectBase, -2); m_pEffectBase->getAnimation()->setFrameEventCallFunc(this, frameEvent_selector(CHeroEvolveEffectLayer::frameEventCallBack)); m_pEffectBase->getAnimation()->setMovementEventCallFunc(this, movementEvent_selector(CHeroEvolveEffectLayer::movementCallBack)); if(m_pEffectForChange!=nullptr) { m_pEffectForChange->removeFromParentAndCleanup(true); } m_pEffectForChange = CCArmature::create("evol"); m_pEffectForChange->setPosition(ccp(DESIGN_WIDTH/2, VIRTUAL_FIXED_HEIGHT/2)); m_pUI->addChild(m_pEffectForChange, -2); m_pEffectForChange->getAnimation()->setFrameEventCallFunc(this, frameEvent_selector(CHeroEvolveEffectLayer::frameEventCallBack)); m_pEffectForChange->getAnimation()->setMovementEventCallFunc(this, movementEvent_selector(CHeroEvolveEffectLayer::movementCallBack)); }
void GameCharacterShape::playAction(const std::string& actionName, bool loop, ActionFrameEventCallback eventCallBack) { // @_@ 需要检查一下是否有指定动画 std::vector<std::string> tmpNames = _armature->getAnimation()->getAnimationData()->movementNames; for (int i = 0; i < tmpNames.size(); i++) { if (tmpNames[i] == actionName) { if (isNotInAnimation() || _currentAnimationName != actionName) { _armature->getAnimation()->play(actionName, -1, loop ? 9999999 : 0); _currentAnimationName = actionName; _frameEventCallBack = eventCallBack; // 设置帧事件的回调函数 _armature->getAnimation()->setFrameEventCallFunc(this, frameEvent_selector(GameCharacterShape::onFrameEvent)); } return; } } // 如果没有动画可以播放,就播放一个一定存在的动画idle playAction(IDLE_ACTION); }
void TestColliderDetector::onEnter() { CCLayer::onEnter(); scheduleUpdate(); //! load data CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("Cowboy.ExportJson"); //! create armature armature = cocos2d::extension::CCArmature::create("Cowboy"); armature->getAnimation()->play("FireWithoutBullet"); armature->getAnimation()->setSpeedScale(0.2f); armature->setScaleX(-0.2f); armature->setScaleY(0.2f); armature->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width * 0.2, CCDirector::sharedDirector()->getVisibleSize().height * 0.5)); //! bind armature's frame event to onFrameEvent armature->getAnimation()->setFrameEventCallFunc(this, frameEvent_selector(TestColliderDetector::onFrameEvent)); addChild(armature); //! create armature2 armature2 = cocos2d::extension::CCArmature::create("Cowboy"); armature2->getAnimation()->play("Walk"); armature2->setScaleX(-0.2f); armature2->setScaleY(0.2f); armature2->setPosition(ccp(CCDirector::sharedDirector()->getVisibleSize().width * 0.8, CCDirector::sharedDirector()->getVisibleSize().height * 0.5)); addChild(armature2); //! add a CCPhysicsSprite,will show in FrameEvent bullet = CCPhysicsSprite::createWithSpriteFrameName("25.png"); addChild(bullet); initWorld(); }
bool EnemyZ::init() { if (!CCArmature::init("EnemyZAnimation")) { return false; } this->m_gold=80; this->m_goldPercentage=0.5f; this->setExperience(20); this->setHitPoints(100.0); //受到的伤害 this->setDamage(10.0); this->setWalkSpeed(100.0); //走路速速 this->setScale(0.4); this->scale=-0.4; //_spriteBox=new SpriteBox(ccp(-20,-55),CCSizeMake(65,80),ccp(-65,-50),CCSizeMake(65,50)); SetSpriteBox(ccp(-20,-55),CCSizeMake(65,80),ccp(-65,-50),CCSizeMake(65,50)); //this->setHitbox(createBoundingBoxWithOrigin(ccp(-20,-55),CCSizeMake(65,80))); //this->setAttackBox(createBoundingBoxWithOrigin(ccp(-65,-50),CCSizeMake(65,50))); this->getAnimation()->setFrameEventCallFunc(this, frameEvent_selector(EnemyZ::onFrameEvent)); this->getAnimation()->setMovementEventCallFunc(this, movementEvent_selector(EnemyZ::animationEvent)); return true; }
/// 导入动画数据 CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("testAnimation/testAnimation0.png","testAnimation/testAnimation0.plist","testAnimation/testAnimation.ExportJson"); m_pArmature = CCArmature::create("testAnimation"); CCArmatureAnimation *pAnimation = m_pArmature->getAnimation(); pAnimation->play("ColorGreen"); // /// 设置动作循环情况 // pAnimation->setLoopType(ANIMATION_TO_LOOP_FRONT); pAnimation->setMovementEventCallFunc(this, movementEvent_selector(HelloWorld::onAnimationEvent)); ///< 监听角色动作状态 pAnimation->setFrameEventCallFunc(this, frameEvent_selector(HelloWorld::onFrameEvent)); ///< 设置帧监听事件 m_pArmature->setPosition(ccp(200, 200)); addChild(m_pArmature, 1); void HelloWorld::onAnimationEvent( cocos2d::extension::CCArmature *pArmature, cocos2d::extension::MovementEventType eventType, const char *animationID ) { /// LOOP_COMPLETE 只有在动作是循环播放时,且每循环一次响应一次 if (eventType == LOOP_COMPLETE) { CCLOG("LOOP_COMPLETE"); } if (eventType == START) { CCLOG("START"); } /// COMPLETE--只有在动作设置为不循环播放时才在动画结束响应一次 if (eventType == COMPLETE) { CCLOG("COMPLETE"); }