首先需要声明一个全局的table——gFlashTable = {}
还需要声明一个全局的标记——gFlashIsPlay = false 用于判断当前是否有动画正在播放。
在需要播放动画的地方,将创建的动画加入到teble中,如:
local animation = ccs.Armature:create("xxx")
table.insert(gFlashTable , animation)
我们再来看如何进行队列播放
首先需要判断gFlashTable长度是否为0 , 其次再判断当前是否有动画正在播。有了这个思路,就很好实现了。
function xx:playFlashWithSequence()
if #gFlashTable ~= 0 then
if gFlashIsPlay then
return
else
local function animationEvent(armatureBack,movementType,movementID)
if movementType == ccs. MovementEventType.complete then
table.remove(gFlashTable , 1)
gFlashIsPlay = false
self:playFlashWithSequence()
end
end
gFlashTable[1]:getAnimation():playWithIndex(0) gFlashTable[1]:getAnimation():setMovementEventCallFunc(animationEvent)
gFlashIsPlay = true
end
end
end
我们永远就只播table中的第一个动画,播放完就移除掉,并将标记设为false。
通过animationEvent这个回调函数来执行播放完后的操作,递归调用这个函数。
我们在向table中增加内容时就可调用这个函数,为了避免重复调用,我们可以做一个判断
if gFlashIsPlay then
xx:playFlashWithSequence()
end
这样第一个动画创建完成的时候就会立即播放,然而在该动画没播放完之后增加的会在它播放完之后进行播放。这样就不会造成屏幕上同时出现多个动画叠加的情况了。
有便于在debug模式下进行效果的调试。