Unsubscribe from resizecanvas event

he …
i’m switching scenes and have learened that i have to manage event subscriptions. i have a last issue which involves

this.app.graphicsDevice.on('resizecanvas', function(){ //doing things },this);

i use it for placing ui elements when changing screen resolution in one scene. when switching back from the other scene the event callback now misses objects while at the same time working. i assume that this:

this.app.graphicsDevice.off('resizecanvas');

is not quite how it works. or am i missing something else?

Hi @rtz23,

.off() generally should work, but for this specific event it may not be that simple.

If you avoid using an anonymous function as your event handler then you can easily target and remove it like this:

// --- call a script method named onResize
this.app.graphicsDevice.on('resizecanvas', this.onResize,this);

this.app.graphicsDevice.off('resizecanvas', this.onResize,this);
1 Like

@Leonidas

thank you, that helped. also needed to figure out the right time to remove it. works now…

1 Like