监听事件

q87551191
Mon, 15 Aug 2016 14:38:54 +0000

onLoad: function () {
    this.time = 0 ;
    this.counting = false ;
    this.getComponent(cc.Label).string = this.counting;
    this.startgame.on('start',this.startcount,this.node);    //监听1
   // this.startcount();            //直接执行
},

startcount:function(){
    this.counting = true ;
    this.getComponent(cc.Label).string = this.counting ;
},

update:function (dt) {
    if (this.counting) {
        this.time += dt;
        this.getComponent(cc.Label).string = this.time.toFixed(2) + ' s';
    }
}

备注中“直接执行”，startcount 可以将this.counting变成true.从而执行update,但是从监听1进入，则update不会执行，这是为什么。。。确认监听到事件了，label有显示

阅读整个主题