第一步:
在组件上,挂载 LuaLooper 脚本(这是驱动tolua里面Update)
第二步:
找到tolua 里面的event 脚本 把下面代码复制进来
function _event:Add(func,obj)
local events = UpdateBeat:CreateListener(func,obj)
UpdateBeat:AddListener(events)
UpdateBeat(func)
return events
end
func 是你要执行的update,obj 是这个update所在的表
第三步:
local this = {}
this.events
–需要执行的时候写下面这行代码
this.events = UpdateBeat:Add(this.Update,this)
–移除Update
–UpdateBeat:RemoveListener(this.events)
function this.Update()
print(‘我被调用了’)
end
return this
–这就是 在tolua里调用Update
本文详细介绍了如何在tolua中设置Update循环,通过挂载LuaLooper脚本并利用UpdateBeat监听器,实现Lua脚本的定时更新功能。文章提供了具体代码示例,包括添加和移除Update循环的方法。
2906

被折叠的 条评论
为什么被折叠?



