question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@pixi/events Masked container with nested child containers doesn't bubble events.

See original GitHub issue

Expected Behavior

Grandchild’s event listeners should work as they do with non masked grandparent.

Current Behavior

Grandchild’s event listeners are not triggered if it’s grandparent is masked.

Steps to Reproduce

See running example.

Create following hierarchy:

Container with mask and interactive -> Container without any event listeners or mask – -> Displayobject with eventlistnener

Test with mask enabled: Does not work. Comment out adding mask: Does work.

Environment

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
domis86commented, Apr 10, 2022

@ShukantPal very good and clear explanation! 👍

1reaction
ShukantPalcommented, Apr 10, 2022

It’s not a bug, explanation

I’ve done some investigating and this is not a bug. In your code, you have the following scene graph structure:

Stage
 |
Container
 |
Container, Mask
|          |
Button     (no children)

This means the mask is like any other DisplayObject and it’ll capture events passing it’s hit-test if one of it’s ancestors is interactive. Indeed, the mask you’ve added is a 75px square that’s transparent and it is rendered above the red button. That’s why the hitTestRecursive method returns a 0-length array on the mask (it passes hit testing but since it’s not interactive, it isn’t included in the propagation path of the ensuing pointerdown event):

Screen Shot 2022-04-09 at 10 07 07 PM

What you can do about it!

1 − (suboptimal) Reorder your scene graph

You can reorder the children of the grandparent container, such that the mask comes before the button. This will cause the hit-testing algorithm to prioritize the button over the mask.

However, the mask will continue to capture events that happen outside the button but inside the mask.

2 − (optimal) Set visible to false on the mask

You can instead set the visible flag on the mask to false. The hit-testing algorithm will ignore these invisible objects.

I’ve updated the playground you’ve attached to this issue to demonstrate the fix.

Screen Shot 2022-04-09 at 10 17 39 PM

https://www.pixiplayground.com/#/edit/t5WBOFp3-SBRfYvedOxe1

Read more comments on GitHub >

github_iconTop Results From Across the Web

PIXI.Container - PixiJS API Documentation
Container is a general-purpose display object that holds children. ... At the moment, CanvasRenderer doesn't support Sprite as mask.
Read more >
Interaction - PixiJS
First, events in PixiJS do not "bubble", meaning you cannot set an event trigger on a parent object and have it fire when...
Read more >
JS: Why would click event not be bubbling? - Stack Overflow
I have a click event on a child nested within a parent element. I am logging the target of the event but the...
Read more >
Nested Containers - Phaser 3
Applying mask to Widget itself works and clips its children well,. but applying same mask to the childrenContainer does not work at all....
Read more >
Profiles and Child Containers - StructureMap
Child Containers are not interchangeable with Nested Containers. ... ShouldBeOfType<ChildSpecialService>(); // The child container does not have any ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found