码迷,mamicode.com
首页 > 其他好文 > 详细

定时器暂停以及完全删除

时间:2014-08-11 17:20:42      阅读:321      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   cti   div   new   

 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;
};

 

 

定时器暂停以及完全删除,布布扣,bubuko.com

定时器暂停以及完全删除

标签:style   blog   color   io   ar   cti   div   new   

原文地址:http://www.cnblogs.com/doghouse/p/3904861.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!