加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

cocos的TargetedAction动作类的使用

发布时间:2020-12-14 21:26:33 所属栏目:百科 来源:网络整理
导读:TargetedAction是一个将动作与弄得绑定的类,通过它可以将自己想要给node添加的动作绑定在一起,这样在调用runAction(ActionInterval);的方式,绑定的node就会执行你绑定动作。有些人会问单纯的用node-runAction(actionInterval);不是也可以,这样岂不是多此

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读