首页 > 代码库 > 定时器暂停以及完全删除
定时器暂停以及完全删除
1 var SchedulerPauseResumeTest = cc.Layer.extend({ 2 ctor : function(){ 3 this._super(); 4 //添加监听 5 6 this.schedule(this.onTick1, 0.5); 7 this.schedule(this.onTick2, 0.5); 8 this.schedule(this.onPause, 3); 9 },10 onTick1:function (dt) {11 logTest("tick1");12 },13 onTick2:function (dt) {14 logTest("tick2");15 },16 onPause:function (dt) {17 cc.Director.getInstance().getScheduler().pauseTarget(this);18 }19 });20 21 SchedulerPauseResumeTest.create = function(args){22 var layer = new SchedulerPauseResumeTest();23 return layer.init() ? layer : null;24 };
展示如何暂停事件.
展示如何删除事件
var SchedulerUnscheduleAllTest = cc.Layer.extend({ ctor : function(){ this._super(); this.schedule(this.onTick1, 0.5); this.schedule(this.onTick2, 1.0); this.schedule(this.onTick3, 1.5); this.schedule(this.onTick4, 1.5); this.schedule(this.onUnscheduleAll, 4); }, onTick1:function (dt) { logTest("tick1"); }, onTick2:function (dt) { logTest("tick2"); }, onTick3:function (dt) { logTest("tick3"); }, onTick4:function (dt) { logTest("tick4"); }, onUnscheduleAll:function (dt) { this.unscheduleAllCallbacks(); }});SchedulerUnscheduleAllTest.create = function(args){ var layer = new SchedulerUnscheduleAllTest(); return layer.init() ? layer : null;};
还有一种是硬删除:
var SchedulerUnscheduleAllHardTest = cc.Layer.extend({ ctor : function(){ this._super(); this.schedule(this.onTick1, 0.5); this.schedule(this.onTick2, 1.0); this.schedule(this.onTick3, 1.5); this.schedule(this.onTick4, 1.5); this.schedule(this.onUnscheduleAll, 4); }, onTick1:function (dt) { logTest("tick1"); }, onTick2:function (dt) { logTest("tick2"); }, onTick3:function (dt) { logTest("tick3"); }, onTick4:function (dt) { logTest("tick4"); }, onUnscheduleAll:function (dt) { cc.Director.getInstance().getScheduler().unscheduleAllCallbacks(); }});SchedulerUnscheduleAllHardTest.create = function(args){ var layer = new SchedulerUnscheduleAllHardTest(); return layer.init() ? layer : null;};
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。