看到官方文档是有个unschedule的方法,但是不知道怎么调用,我看到入参target,但并不知道是啥。
我的使用场景是,显示一个label,cc.director.getScheduler().schedule(),3秒后执行隐藏。
但是用户可能在3秒内再次触发这个定时器,这时候隐藏的函数可能刚好开始执行,这样导致label闪一下就消失了。
我的想法是每次显示之前,先移除之前的消失定时器。
看到官方文档是有个unschedule的方法,但是不知道怎么调用,我看到入参target,但并不知道是啥。
我的使用场景是,显示一个label,cc.director.getScheduler().schedule(),3秒后执行隐藏。
但是用户可能在3秒内再次触发这个定时器,这时候隐藏的函数可能刚好开始执行,这样导致label闪一下就消失了。
我的想法是每次显示之前,先移除之前的消失定时器。
我记得传入的target就是这个定时器
cc.director.getScheduler().unschedule(function () {
console.log('test')
}, showSchedule)
this.tipBox.runAction(action)
const delayOut = function(){
const action = cc.fadeTo(1.0,0)
this.tipBox.runAction(action)
}
showSchedule = cc.director.getScheduler().schedule(delayOut,this,3,1,0,false);
我这样写不行啊?
望大神指点
‘’’
let Index = 100;
this.mIndex = 0;
let funUp = function () {
this.mIndex ++;
// 等于 100 的时候停止计时器回调
if (Index <= this.mIndex) {
this.unschedule(funUp);
}
}
this.schedule(funUp, newTime);
‘’’
好的,谢谢,搞定了