TargetedAction是一个将动作与弄得绑定的类,通过它可以将自己想要给node添加的动作绑定在一起,这样在调用runAction(ActionInterval);的方式,绑定的node就会执行你绑定动作。有些人会问单纯的用node->runAction(actionInterval);不是也可以,这样岂不是多此一举么?其实不然,下面我们来看一下代码:
{
ProgressTimer *progress = dynamic_cast<ProgressTimer*> (mLayout->getChildByName("progressTimer"));
Vector<FiniteTimeAction*> actVec;
if ((curEXp + gainExp) > culLevelNeedExp)
{
TargetedAction *t0 = TargetedAction::create(progress,ProgressTo::create(0.7f,100));
TargetedAction *t1 = TargetedAction::create(progress,ProgressTo::create(0.1f,0));
CallFunc *func = CallFunc::create([=](){
lvAlt->setString(StringUtils::format("%d",level + 1).c_str());
});
Sequence *seq = Sequence::create(t0,t1,func,nullptr);
actVec.pushBack(seq);
int disExp = gainExp - (culLevelNeedExp - curEXp);
auto needexp = ObjConfig::getInstance()->getHeroConfig(++level)->getNeedExp();
while (disExp > needexp)
{
disExp -= needexp;
needexp = ObjConfig::getInstance()->getHeroConfig(++level)->getNeedExp();
TargetedAction *t2 = TargetedAction::create(progress,100));
TargetedAction *t3 = TargetedAction::create(progress,0));
CallFunc *tFunc = CallFunc::create([=](){
lvAlt->setString(StringUtils::format("%d",level + 1).c_str());
});
Sequence *tseq = Sequence::create(t2,t3,tFunc,nullptr);
actVec.pushBack(tseq);
}
float per = disExp * 1.0 / needexp * 100;
TargetedAction *tn = TargetedAction::create(progress,per));
actVec.pushBack(tn);
int indexSize = actVec.size();
Sequence *actSeq = Sequence::create(actVec);
this->runAction(actSeq);
}
else
{
CCLOG("do this chaptor");
TargetedAction *t = TargetedAction::create(progress,percent));
this->runAction(t);
}
}
是这样的,node执行动作的时候除了使用spawn可以同时执行多个动作外,其他情况下你直接调用node->runAction(actionInterval);效果不是你想要的效果的,不信你可以试试。第一次写博客,写的不好请不要喷。