Event scope

Hello, I am new to Phaser3 and am struggling with buildling UIs.

As far as I know, Phaser3 doesn’t support UIs such as layouts, buttons, lists, etc.

So I am trying to build my own flexible Phaser3 UI.

I built Widget class as the root class of all my UI elements.

The first problem is that I want my Widget to handle it’s own events and consume it.

Howerver, if I do setInteractive() to a Widget, it will not consume the event and the Scene will always respond the the event.

Are there any good ways to consume events or limit event to be called inside specific scope?

Assuming Widget extends GameObject, then it already has an Event Emitter built into it. Which means it can already emit any custom event you need. What you have bound as a listener is up to you, though. If you make it interactive, then there is nothing stopping you binding the input events to methods on the Widget. The Widget will emit pointerdown etc, on itself, so you could listen for those and handle them without it ever touching the Scene.

1 Like

Ohhh… So the event is emitted to the GameObject itself instead of the Scene… Thanks!!

The Game Object itself will emit some input events. Where you bind the listeners for those is up to you, but the events never touch the Scene. In fact, thinking about it, there isn’t a single Input event from anywhere that goes to the Scene!