定时器

来源:互联网 发布:珠江钢琴天猫淘宝 编辑:程序博客网 时间:2024/06/02 02:00
/**
 * Created by Administrator on 2017/4/21.
 */
var TestLayer = cc.Layer.extend({
    ctor:function(){
        /***********************scheduleUpdate系统定时器***********************/
        this.scheduleUpdate();//调用update函数
        /***********************schedule自定义定时器***********************/
        this.schedule(this.updateData.bind(this),1,cc.REPEAT_FOREVER,0.1,"");
        /***********************scheduleOnce只调用一次定时器***********************/
        this.scheduleOnce(this.updateD.bind(this),0.1,"");


        /***********************获取当前的时间***********************/
        setTimeout(function(){
            trace("pause", this.currentTime());
            this.pause();
        }.bind(this), 2000);


        setTimeout(function(){
            trace("resume", this.currentTime());
            this.resume();
        }.bind(this), 5000);
    },
    update: function (dt) {
        //每0.02s调用一次
    },
    updateData: function () {
        //会根据this.schedule第二个参数的时间来调用updataData函数
    },
    updateD: function () {
        //只调用一次
    },
    currentTime: function () {
        return parseInt(new Date().getTime()/1000);
    }




});