
Repeat这个Action的本意是可以方便地对某一个动画执行指定的次数,比如这段代码:
scene.index = 0 --延时 local delayAction = cc.DelayTime:create(0.5) --回调 local callFuncAction1 = cc.CallFunc:create(function() scene.index = scene.index + 1 cclog("index: %d",scene.index) end) --序列 local sequenceAction = cc.Sequence:create(delayAction,callFuncAction1) --重复 local repeatAction = cc.Repeat:create(sequenceAction,2) scene.action1 = scene:runAction(repeatAction)
它的执行结果是:
cocos2d: [LUA-print] index: 1 cocos2d: [LUA-print] index: 2
执行了两次,不错。尝试将次数从2改为3:
local repeatAction = cc.Repeat:create(sequenceAction,3)
执行结果是:
cocos2d: [LUA-print] index: 1 cocos2d: [LUA-print] index: 2 cocos2d: [LUA-print] index: 3
嗯,3次,不错。现在,见证奇迹的时刻到了,把delayAction的0.5秒改为0.1秒,保持次数依然为3次不变:
local delayAction = cc.DelayTime:create(0.5) ... local repeatAction = cc.Repeat:create(sequenceAction,51); Font-family:Arial; Font-size:14px; line-height:26px"> 再次执行,结果居然是执行了4次!!cocos2d: [LUA-print] index: 1 cocos2d: [LUA-print] index: 2 cocos2d: [LUA-print] index: 3 cocos2d: [LUA-print] index: 4研究许久,无任何结论,巨坑一个,甚至有些情况下在CallFunc内去stopAction都不起作用,简单来说,就是珍爱生命,远离Repeat这个神经病。
总结以上是内存溢出为你收集整理的cocos2d-x + Lua的cc.Repeat动画执行次数不准,巨坑全部内容,希望文章能够帮你解决cocos2d-x + Lua的cc.Repeat动画执行次数不准,巨坑所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)