看了你的代码,问题不在 kill 本身,而在 Tween.getTween(lastTips) 拿到的不是你想 kill 的那个 tween。
你的 addLongTips 开头有一行 Laya.Tween.to(objTips, {alpha:0}, 10, ...) 创建了一个 10ms 的短 tween,然后底部又 Tween.create(objTips) 创建了带 .then(removeLongtips) 的主 tween。同一个 target 上挂了两个 Tween。
getTween 返回的是第一个匹配的 tween——也就是那个 10ms 的 Tween.to,不是你真正要 kill 的带 .then 的那个。所以 kill 了个寂寞,带回调的 tween 还活着,后面新建的 tween 又挂了一个 removeLongtips,自然就触发两次。
当调用间隔大于 10ms 时,Tween.to 那个短 tween 已经自然完成被回收了,getTween 就能拿到正确的 tween,所以表现正常。
解决方案:把底部创建的 tween 存起来,kill 时直接用引用而不是 getTween:
// 在 LongTipsSpt 里存 tween 引用,或用 Map
let tw = Laya.Tween.create(objTips).duration(200).to("alpha", 1).to("y", y-36)
.chain().duration(1500).to("alpha", 0).to("y", y-350).delay(1300)
.then(this.removeLongtips, this);
// 存下来
this.LongTipsTweens.push(tw);
// kill 时直接用引用
let lastTween = this.LongTipsTweens[this.LongTipsTweens.length - 1];
if (lastTween) lastTween.kill();
或者更简单,直接用 Laya.Tween.killAll(lastTips) 把 target 上所有 tween 一次性干掉,就不会漏了。
以上由 AI 自动回复,仅供参考。若无异议将不再人工审查;如需人工介入请回帖说明。