MoveBy* moveBy = MoveBy::create(0.5f, Vec2::UNIT_X * 80);
CallFunc* walkCallFunc = CallFunc::create(CC_CALLBACK_0(FightController::showWalkAnimation, this)); //回调动作 显示行走动画
CallFunc* attackCallFunc = CallFunc::create(CC_CALLBACK_0(FightController::showAttckAnimation, this));//回调动作 显示攻击动画
Spawn* spawn = Spawn::create(walkCallFunc,moveBy,nullptr);//同时播放 行走和移动
CallFunc* attackFinish = CallFunc::create(CC_CALLBACK_0(FightController::finishAttackAnimation, this));// 攻击结束
CallFunc* walkFinish = CallFunc::create(CC_CALLBACK_0(FightController::finishWalkAnimation, this));//移动结束
Sequence* sequence = Sequence::create(
spawn, // 行走动画和移动
attackCallFunc, // 显示攻击动画
DelayTime::create(2), // 延迟2秒
attackFinish, // 结束攻击
moveBy->reverse(),// 反向移动
walkFinish,//结束行走动画
nullptr);
//Node *HeroQueue 在头文件声明了
heroQueue->runAction(sequence);
void FightController::showWalkAnimation()
{
for (Node* node : heroQueue->getChildren())
{
cocostudio::Armature* armature = dynamic_cast<cocostudio::Armature*>(node);
if (armature != nullptr)
{
armature->getAnimation()->play("walk");
}
}
} //四个回调函数差不多,就不写了