日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

lua cocos 动画回调

發布時間:2024/4/11 编程问答 44 豆豆
生活随笔 收集整理的這篇文章主要介紹了 lua cocos 动画回调 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

最近項目有用到播放一個骨骼動畫,播放完成后,啟動另外一個動畫,在此使用骨骼動畫的回調函數實現。過程如下:
一、實現動畫播放結束后的回調

1、得到動畫,播放動畫,并設置動畫的回調函數 local armature = self._viewNode.amture(自己定義的骨骼動畫) armature:getAnimation():play("hall_light")--(設置動畫回調函數animationEvent) armature:getAnimation():setMovementEventCallFunc(animationEvent) 2、動畫回調函數的實現在此屏蔽動畫開始事件: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、動畫結束后執行的函數 function callback1()--執行動畫結束后的操作 end

二、停止動畫回調

function stopArmatureCallBack()amrature:stopAllActions()amrature:getAnimation():setMovementEventCallFunc(function() end)amrature:getAnimation():setMovementEventCallFunc(assert)end

三、代碼完整展現
實現動畫2s循環播放

function MainCtrl:startNeonLightAni()local animationEvent = nillocal 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

總結

以上是生活随笔為你收集整理的lua cocos 动画回调的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。