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