(博主qq,1204802552,欢迎交流)
有时候,我们想在Sequence或者Spawn中加入RepeatForever的动作,但在实际运行中,该循环动作并未得到执行,我们先来说下解决的方法。
对于Spawn,很简单,我们只需要把RepeatForever动作拿出来单独执行即可
Animation *animation = Animation::createWithSpriteFrames(aniframe,0.1f);
Animate *animate = Animate::create(animation);
aniSprite->runAction(RepeatForever::create((ActionInterval *)animate));
aniSprite->runAction(MoveTo::create(5,PointMake(visibleSize.width-40, visibleSize.height/2)));
对于Sequence,则要使用回调函数来执行RepeatForever动作
CallFunc *callfunc = CallFunc::create(this,callfunc_selector(HelloWorld::animateCallback));
Action * seq = Sequence::create(MoveTo::create(5,PointMake(visibleSize.width-40, visibleSize.height/2)),callfunc,NULL);aniSprite->runAction(seq);
下面分析下具体原因:Spawn和Sequence都采用递归的创建方式
我们先来看看Spawn的创建源码:Spawn有不同形式的Create函数,但最终它们