Jump to content

Interaction propogation


alex_h
 Share

Recommended Posts

I often have interactive sprites in different containers, some of which move around. This means I sometimes end up with two interactive sprites in different branches of the display tree but at the same global 'stage' co-ordinates. Currently this means that they will both respond to a mouse press or touch down event. I am looking for a simple way to detect that the sprite that is 'in front' has responded to the interaction and stop it from additionally triggering my event handler in the sprite that is 'behind'.

I'm using pixi 3.09

[Edit]

If I modify the pixi interaction manager so that when there is a hit it breaks out of its repeat loop then this achieves the effect I'm looking for. Would be interesting to know why it doesn't do this, is there some penalty I'm missing?

for (var i = children.length-1; i >= 0; i--)
        {
            // time to get recursive.. if this function will return if somthing is hit..
            if( this.processInteractive(point, children[i], func, hitTest, interactiveParent) )
            {
                hit = true;
                // we no longer need to hit test any more objects in this container as we we now know the parent has been hit
                interactiveParent = false;

                // If the child is interactive , that means that the object hit was actually interactive and not just the child of an interactive object.
                // This means we no longer need to hit test anything else. We still need to run through all objects, but we don't need to perform any hit tests.
                if(children[i].interactive)
                {
                    hitTest = false;
                }
                break;//<<< ---- I just have to add this and then it works
            }
        }

 

Edited by alex_h
further info
Link to comment
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...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...