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


    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() --中止当前的计时器
        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 = 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 = 0
    local handle = nil
    
    function Game.FunTest(f1)
        count = count + 1
        print(f1,count)
        if count > 10 then
           FixedUpdateBeat:RemoveListener(handle)
        end
    end
    
    --初始化完成,发送链接服务器信息--
    function Game.OnInitOK()
        local parm = 0
        handle = FixedUpdateBeat:CreateListener(Game.FunTest, parm) --好像只支持一个参数 
        FixedUpdateBeat:AddListener(handle) 
    end
  • 相关阅读:
    springboot(eureka子项目)+idea+jsp 404问题
    什么是区块链以及他的6个特征?
    elasticsearch启动时提示内存不足错误的解决方法
    ElasticSearch 安装root用户启动失败问题解决
    防抖节流(立即执行和延时执行)
    将数字转为千分制格式(最简单)
    微信H5跳转任意小程序
    原生html+css设置项目主题色(超简单)
    H5获取手机型号
    css属性——env()和constant()设置安全区域
  • 原文地址:https://www.cnblogs.com/vsirWaiter/p/8108888.html
Copyright © 2020-2023  润新知