博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ulua/tolua中timer.lua和event.lua的使用(Luaframework)
阅读量:4489 次
发布时间:2019-06-08

本文共 1915 字,大约阅读时间需要 6 分钟。

Timer.lua

Timer计时器:

 

 local tim = nil

 local count = 0

function Game.FunTest()    count = count + 1    print(0,0,0,count)    if count > 4 then        tim:Stop() --中止当前的计时器    endend--初始化完成,发送链接服务器信息--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 = 0  local 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 = 0local handle = nilfunction Game.FunTest(f1)    count = count + 1    print(f1,count)    if count > 10 then       FixedUpdateBeat:RemoveListener(handle)    endend--初始化完成,发送链接服务器信息--function Game.OnInitOK()    local parm = 0    handle = FixedUpdateBeat:CreateListener(Game.FunTest, parm) --好像只支持一个参数     FixedUpdateBeat:AddListener(handle) end

 

转载于:https://www.cnblogs.com/vsirWaiter/p/8108888.html

你可能感兴趣的文章
作业4
查看>>
LeetCode "Divide Two Integers"
查看>>
mcs51 串口通信 单片机发 pc收
查看>>
MySQL ACID及四种隔离级别的解释
查看>>
text-align 属性,输入框数字向右靠
查看>>
debian分区方案(就这个看着靠谱点)转
查看>>
虫师Selenium2+Python_11、自动化测试项目实战
查看>>
模拟竖式除法
查看>>
java调用dll
查看>>
图形界面组件实验的一点总结
查看>>
django 1.11.16之环境搭建
查看>>
15.SpringMVC和Spring上下文关系(为什么SpringMVC可以调用到Spring)
查看>>
Syncfusion的社区许可及免费电子书和白皮书
查看>>
JAVA自学作业02
查看>>
蛇形矩阵
查看>>
活动选择
查看>>
7832:最接近的分数
查看>>
初识window phone 7程序
查看>>
思维导图
查看>>
XE6 c++builder Edit垂直居中
查看>>