The reason why your .remove()
function doesn't remove the function is because when you use an arrow function you're creating a new function each time. So it tries to remove a new function that it just created instead of the function inside of the .add()
.
I think you're wanting to do something like this? Demo
animate() {
const myThis = window.tunnel;
try {
// Working version
myThis.renderer.render(myThis.scene, myThis.camera);
// Error version (to show it works)
// this.renderer.render(this.scene, this.camera);
} catch (error) {
gsap.ticker.remove(myThis.animate);
console.error(error);
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…