Hundreds of features to explore
Games made in Construct
Your questions answered
Trusted by schools and universities worldwide
Free education resources to use in the classroom
Students do not need accounts with us
What we believe
We are in this together
World class complete documentation
Official and community submitted guides
Learn and share with other game developers
Upload and play games from the Construct community
Game development stories & opinions
I tried it in many ways and it's still not removed
runtime.removeEventListener("tick",Tick);
runtime.removeEventListener("tick",() => Tick(runtime));
But why do you want to do this?
Have you tried deleting these lines of code?
runOnStartup(async runtime => { runtime.addEventListener("beforeprojectstart", () => OnBeforeProjectStart(runtime)); }); function OnBeforeProjectStart(runtime) { runtime.addEventListener("tick", () => Tick(runtime)); } function Tick(runtime) { }
Or these?
runtime.addEventListener("tick", () => Tick(runtime));
Develop games in your browser. Powerful, performant & highly capable.
I just tried it and it works for me.
You have to make sure you pass exactly the same function reference to both addEventListener and removeEventListener. If you do this:
addEventListener
removeEventListener
then you haven't saved the function reference anywhere, so it's impossible to remove it. Instead you have to save the function reference to a variable like this:
const tickFunc = () => Tick(runtime); runtime.addEventListener("tick", tickFunc); // later on... runtime.removeEventListener("tick", tickFunc);
That ensures you pass the same function reference to both methods. Note if you try to remove () => Tick(runtime) again, or just Tick, those are both different functions to the one you added the event with so it won't work.
() => Tick(runtime)
Tick