定时器的合并和变速

schedule1:null,
schedule2:null,
ctor:function () {
    this._super();
    this.schedule1 = {
        target:3,   //��¼����Ŀ��ֵ
        current:0,  //��¼���ǵ���ֵ
        handler:this.handler1,
    }
    this.schedule2 = {
        target:2,
        current:0,
        handler:this.handler2,
    }
    this.scheduleUpdate()
    var that = this;
    var listener = cc.EventListener.create({
        event:cc.EventListener.TOUCH_ONE_BY_ONE,
        swallowTouches:true,
        onTouchBegan:function(touch, event){
            that.schedule1.target = 1   //����Ϊ1����
            return true;
        },
    });
    cc.eventManager.addListener(listener, this);
},
update:function(offset){
    this.schedule1.current += offset
    if(this.schedule1.current > this.schedule1.target){ //������ʱ��
        this.schedule1.handler()
        this.schedule1.current = this.schedule1.current - this.schedule1.target//�����ۼ����
    }

    this.schedule2.current += offset
    if(this.schedule2.current > this.schedule2.target){ //������ʱ��
        this.schedule2.handler()
        this.schedule2.current = this.schedule2.current - this.schedule2.target//�����ۼ����
    }
},
handler1:function(){
    cc.log('this is handler1')
},
handler2:function(){
    cc.log('this is handler2')
},

你可能感兴趣的:(定时器的合并和变速)