Sign in to follow this  
cachopixi

Prevent event from propagating to parent

Recommended Posts

If I have a container and a child of it, and both have "interactable" set to true.

I noticed that if I click on the child, both the child and its container get the event.

How can I prevent the event from propagating to the parent?

Ie. imagine the container is the play area, and on top of it there's objects. If I click the play area I expect the character to move there. If I click an object, I expect to interact with it, and stop the propagation there, so it doesn't get to the play area callback.

Thanks!

Share this post


Link to post
Share on other sites

hum make a flag in parent and when the child event are call , check if the parent event flag are true ?

Maybe there is other solution, but I proceed in this way in complex situations.:)

Link your objet with reference.

Share this post


Link to post
Share on other sites

Thanks! I'm using Typescript, and the default callback parameter was of type DisplayObject so I was not finding stopPropagation(). Ie. :
 

        mySprite.on('click', function (ev) {

        });

 

Forcing an InteractionEvent type worked
 

        mySprite.on('click', function (ev: PIXI.interaction.InteractionEvent) {

             ev.stopPropagation();

        });

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.