ulua/tolua中timer.lua和event.lua的使用(Luaframework)
生活随笔
收集整理的這篇文章主要介紹了
ulua/tolua中timer.lua和event.lua的使用(Luaframework)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Timer.lua
Timer計時器:
?local tim = nil
?local count = 0
FrameTimer計時器:
tim = FrameTimer.New(Game.FunTest,100, 5) --和上面使用的一樣,但參數不一樣,參數1為方法名,參數2和參數3組合起來的意思是在100幀內執行5次方法。tim:Start()CoTimer計時器:
tim = CoTimer.New(Game.FunTest,1, 5) --和上面使用的一樣,但參數不一樣,參數1為方法名,參數2為兩次執行的間隔時間,參數3為執行次數(參數3為-1時無限次數) tim:Start()?
event.lua
UpdateBeat = event("Update", true) ?--邏輯的Update
LateUpdateBeat = event("LateUpdate", true) ?--延遲的update
FixedUpdateBeat = event("FixedUpdate", true) --物理的update
CoUpdateBeat = event("CoUpdate") ?--協程的每一幀更新
調用方式:
?local count = 0 ?
?function Game.FunTest(f1)
? ? count = count + 1
? ? print(f1,count)
? end
function Game.OnInitOK()
local parm = 0local handle = UpdateBeat:CreateListener(Game.FunTest, parm) --好像只支持一個參數 UpdateBeat:AddListener(handle)
local handle = LateUpdateBeat:CreateListener(Game.FunTest, parm) --好像只支持一個參數 LateUpdateBeat:AddListener(handle)
local handle = FixedUpdateBeat:CreateListener(Game.FunTest, parm) --好像只支持一個參數 FixedUpdateBeat:AddListener(handle)
local handle = CoUpdateBeat:CreateListener(Game.FunTest, parm) --好像只支持一個參數 CoUpdateBeat:AddListener(handle)
end ?
?
?event.lua使用FixedUpdateBeat的過程中移除FixedUpdateBeat:
local count = 0 local handle = nilfunction Game.FunTest(f1)count = count + 1print(f1,count)if count > 10 thenFixedUpdateBeat:RemoveListener(handle)end end--初始化完成,發送鏈接服務器信息-- function Game.OnInitOK()local parm = 0handle = FixedUpdateBeat:CreateListener(Game.FunTest, parm) --好像只支持一個參數 FixedUpdateBeat:AddListener(handle) end?
轉載于:https://www.cnblogs.com/vsirWaiter/p/8108888.html
總結
以上是生活随笔為你收集整理的ulua/tolua中timer.lua和event.lua的使用(Luaframework)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SharePoint 集成OWA概述
- 下一篇: Node.js小白开路(一)-- fs篇