日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

ulua/tolua中timer.lua和event.lua的使用(Luaframework)

發布時間:2025/5/22 55 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ulua/tolua中timer.lua和event.lua的使用(Luaframework) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Timer.lua

Timer計時器:

?local tim = nil
?local count = 0

function Game.FunTest()count = count + 1print(0,0,0,count)if count > 4 thentim:Stop() --中止當前的計時器end end--初始化完成,發送鏈接服務器信息-- function Game.OnInitOK()tim = Timer.New(Game.FunTest,1, -1, true) --參數1為調用的方法名,參數2為間隔時間,參數3為循環次數(當為-1時無限循環),參數4為是否忽略時間的Scale,scale false 采用deltaTime計時,true 采用 unscaledDeltaTime計時--tim:Start()tim:Start() end

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)的全部內容,希望文章能夠幫你解決所遇到的問題。

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