生活随笔
收集整理的這篇文章主要介紹了
lua cocos 动画回调
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
最近項目有用到播放一個骨骼動畫,播放完成后,啟動另外一個動畫,在此使用骨骼動畫的回調(diào)函數(shù)實現(xiàn)。過程如下:
一、實現(xiàn)動畫播放結(jié)束后的回調(diào)
1、得到動畫,播放動畫,并設(shè)置動畫的回調(diào)函數(shù)
local armature =
self._viewNode.amture(自己定義的骨骼動畫)
armature:getAnimation()
:play(
"hall_light")--(設(shè)置動畫回調(diào)函數(shù)animationEvent)
armature:getAnimation()
:setMovementEventCallFunc(animationEvent)
2、動畫回調(diào)函數(shù)的實現(xiàn)在此屏蔽動畫開始事件:ccs.MovementEventType.startanimationEvent =
function(armatureBack, movementType, movementID)if movementType == ccs.MovementEventType.start
thenreturnendif armatureBack:isVisible() ==
true thenarmatureBack:stopAllActions()
local delayTime = cc.DelayTime:
create(
2)
local action = cc.Sequence:
create(delayTime,cc.CallFunc:
create(callback1))armatureBack:runAction(action)
endend
3、動畫結(jié)束后執(zhí)行的函數(shù)
function callback1()
end
二、停止動畫回調(diào)
function stopArmatureCallBack()amrature:stopAllActions()amrature:getAnimation():setMovementEventCallFunc(
function() end)amrature:getAnimation():setMovementEventCallFunc(
assert)
end
三、代碼完整展現(xiàn)
實現(xiàn)動畫2s循環(huán)播放
function MainCtrl:startNeonLightAni()local animationEvent = nil
local function callback1()armature:setVisible(
true)armature:getAnimation():play(
"hall_light")
endanimationEvent =
function(armatureBack, movementType, movementID)if movementType == ccs.MovementEventType.start
thenreturnendif armatureBack:isVisible() ==
true thenarmatureBack:stopAllActions()armatureBack:setVisible(
false)
local delayTime = cc.DelayTime:
create(
2)
local action = cc.Sequence:
create(delayTime,cc.CallFunc:
create(callback1))armatureBack:runAction(action)
endendarmature:setVisible(
true)armature:getAnimation():play(
"hall_light")armature:getAnimation():setMovementEventCallFunc(animationEvent)
end
停止動畫的播放
function MainCtrl:stopNeonLightAni()if armature
thenarmature:setVisible(
false)armature:stopAllActions()armature:getAnimation():setMovementEventCallFunc(
function() end)armature:getAnimation():setMovementEventCallFunc(
assert)
end
end
總結(jié)
以上是生活随笔為你收集整理的lua cocos 动画回调的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。