cocos2d-x + Lua的cc.Repeat动画执行次数不准,巨坑

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, 3)

再次执行,结果居然是执行了4次!!

cocos2d: [LUA-print] index: 1
cocos2d: [LUA-print] index: 2
cocos2d: [LUA-print] index: 3
cocos2d: [LUA-print] index: 4

研究许久,无任何结论,巨坑一个,甚至有些情况下在CallFunc内去stopAction都不起作用,简单来说,就是珍爱生命,远离Repeat这个神经病。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值