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这个神经病。

图片描述

图片描述


洪亮
697 声望64 粉丝

引用和评论

0 条评论