cocos-lua学习笔记(十)事件---调度器

第一种是 全局调度器

全局帧调度器

每一帧描画都会触发,windows上窗口移动和最小化的时候会暂停描画。

scheduler.scheduleUpdateGlobal(onInterval) 每一帧调用

全局自定义调度器

指定调度器的时间

scheduler.scheduleGlobal(onInterval, 0.5)  0.5秒调用一次


全局延时调度器

等待指定时间后执行一次回调函数

scheduler.performWithDelayGlobal(onInterval, 0.5)  延时0.5秒调用


local MainScene = class("MainScene", function()
    return display.newScene("MainScene")
end)

local scheduler = require(cc.PACKAGE_NAME .. ".scheduler")

function MainScene:ctor()
	-- 全局帧调度器
	local function onInterval(dt)
		print("update")
	end
	scheduler.scheduleUpdateGlobal(onInterval)

	-- 全局自定义调度器
	local function onInterval(dt)
		print("Custom")
	end
	scheduler.scheduleGlobal(onInterval, 0.5)

	-- 全局延时调度器
	local function onInterval(dt)
		print("once")
	end
	scheduler.performWithDelayGlobal(onInterval, 0.5)
end

return MainScene

大家看一下控制台吧,感觉像是爆炸了。



第二种要介绍的则是 节点调度器

Node是基础类,封装很多基础的方法和属性,其中调度器就是方法之一。

Node中的调度器只能在Node中使用,Node负责管理调度器的生命周期。

大部分情况下,我们使用节点调度器,这样就能把精灵集中在游戏逻辑实现,而不是调度器的生命周期管理。


1.节点桢调度器

2.节点自定义调度器

3.节点延时调度器

local MainScene = class("MainScene", function()
    return display.newScene("MainScene")
end)

local scheduler = require(cc.PACKAGE_NAME .. ".scheduler")

function MainScene:ctor()
	self:schedule(function () print("schedule") end, 1.0)

	self:performWithDelay(function () print("performWithDelay") end, 1.0)
end

return MainScene


停止节点的方法是

node:stopAction(action)


转载于:https://www.cnblogs.com/hiwoshixiaoyu/p/10034962.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值