测试了,你同步我的 PR 就能修复这个了
最后三个字没看明白。
多打了 
之前的逻辑,在一个node被销毁的时候,它上面的定时器会自动销毁。
而现在,一定要手动调用unschedule
这个确实存在,不知道是 panda 设计的还是 bug,到时候我问问他吧,感谢反馈
cc.director.getScheduler().unscheduleAllForTarget 也无法使用,能修复一下吗
怎么个不能用法?最好能给 demo,如果怕麻烦,也请描述详细信息,和代码
const { ccclass, property } = cc._decorator;
@ccclass
export default class TestTimer extends cc.Component {
onLoad() {
this.node.on(“click”, this.OnButtonEnd, this);
this.schedule(this.Test1, 1);
}
onDestroy(){
console.log(“OnDestroy”);
//this.unschedule(this.Test1);
//this.unscheduleAllCallbacks();
cc.director.getScheduler().unscheduleAllForTarget(this);
}
private Test1() {
console.log("Test1");
}
private OnButtonEnd() {
console.log("OnButtonEnd");
this.node.destroy();
}
}
新建一个空项目,放置一个按钮,按钮上绑定这个代码
运行项目,可以看到不断输出“Test1”
点击按钮,打印“OnDestroy”,表示cc.director.getScheduler().unscheduleAllForTarget(this);已经正常执行。
此时可以看到不断输出“Test1”,表示定时器未被销毁
定时器关闭建议还是按原来的来做吧,加一个判定而已,不会多大开销吧?按道理引擎内部创建的定时器,不该上层UI来管理.
你应该是 cc.director.getScheduler().unscheduleAllForTarget(this.node 吧);
啥意思不太明白,你说的原来的做法是什么?
cc.director.getScheduler().unscheduleAllForTarget(this);和cc.director.getScheduler().unscheduleAllForTarget(this.node)都无法清除倒计时;
使用cc.log(cc.director.getScheduler().unscheduleAllForTarget);
打印cc.director.getScheduler().unscheduleAllForTarget
得到的输出是
function unscheduleAllForTarget() {
[native code]
}
好像参数丢了,以前会有一个参数target
如我截图 那样 重写一下就好了
是原生平台才会有这个问题吧?
native平台才有。模拟器也可以出现
panda大大明天才能过来。再等等。
抱歉了,今天才复工,已经修复了这个问题,我们的测试例的确没有覆盖到,现在也完善了一下
https://github.com/cocos-creator/cocos2d-x-lite/pull/948
https://github.com/cocos-creator/engine/pull/2087
重点是第一个 PR 中 native 引擎的修改,需要直接 apply patch 也比较好办,不需要 build
