/**
* Author:W
* 计时器
*/
cc.Class({
extends: cc.Component,
properties: {
},
// LIFE-CYCLE CALLBACKS:
// onLoad () {},
start () {
// this.setSchedule();
// setTimeout(function(){
// this.unSchedule();
// }.bind(this),7000);
this.setSchedule2();
},
//开始计时1
setSchedule:function(){
this.func = function(){
cc.log("每间隔5秒执行1次");
};
this.schedule(this.func,5);
},
//取消计时器
unSchedule:function(){
cc.log("=====计时器取消======");
this.unschedule(this.func);
},
//开始计时2
setSchedule2:function(){
//间隔时间
var interval = 5;
//重复次数
var repeat = 3;
//延迟
var delay = 10;
//开始计时
this.schedule(function () {
cc.log("延迟10秒,每间隔5秒,总共执行3次");
},interval,repeat,delay);
},
//开始计时3
setSchedule3:function(){
//2秒后执行1次,计时器就停止
this.scheduleOnce(function(){
cc.log("秒后执行1次,计时器就停止");
},2);
}
// update (dt) {},
});
计时器
最新推荐文章于 2024-11-05 23:34:27 发布