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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發(fā)布時(shí)間:2025/5/22 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ulua/tolua中timer.lua和event.lua的使用(Luaframework) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Timer.lua

Timer計(jì)時(shí)器:

?local tim = nil
?local count = 0

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

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

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。