cocos的TargetedAction动作类的使用

前端之家收集整理的这篇文章主要介绍了cocos的TargetedAction动作类的使用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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);效果不是你想要的效果的,不信你可以试试。第一次写博客,写的不好请不要喷。

原文链接:https://www.f2er.com/cocos2dx/342780.html

猜你在找的Cocos2d-x相关文章