将cc.repeatForever放进cc.Sequence

在cc.Sequence中加入cc.RepeatForever时,发现其他动作执行没问题,就是到cc.RepeatForever无法执行,出现提示

[Action update]. override me

在stackoverflow上找到了原因是cc.Sequence中只能加入有限时间的动作。

借鉴下csdn中找到的在cocos2d-x中的两个解决思路(推荐第二种):

1.如果是帧动画的话可以使用setLoops(-1)来代替cc.RepeatForever。

(在湖闻樟注:测试了下,这个办法在cocos2d-js 3.6.1中会造成序列中所有的动作失效)

2.把cc.RepeatForever放进cc.callFunc里(推荐)。

 var sprite = cc.Sprite("#animation0.png");
 var anime = cc.sequence(cc.delayTime(1), cc.callFunc(function(){
     var Frames = [];
     for (var i = 0;i < 8; i++){
         var str = "animation";
         var frame = cc.spriteFrameCache.getSpriteFrame(str + i + ".png");
         Frames.push(frame);
     }
     var Animation = new cc.Animation(Frames, 0.1);
     this.runAction(cc.repeatForever(cc.animate(Animation)))
 }.bind(sprite))); //cc.repeatForever不能直接放进cc.sequence里
sprite.runAction(anime);


具体原因请看参考资料。

参考资料:

http://stackoverflow.com/questions/25228032/cocos2d-js-cc-delaytime-and-cc-repeatforever-dont-work-together-in-cc-sequ

http://blog.csdn.net/jackystudio/article/details/17019023

你可能感兴趣的:(游戏,cocos2d-js)