Jump to content

Input events propagation


Recommended Posts

I have a very trivial nested-sprites situation, similar to this:

function create() {

    var sprite = game.add.sprite(0, 0, 'phaser');
    sprite.width = 100;
    sprite.width = 100;
    sprite.inputEnabled = true;
    sprite.events.onInputDown.add(function(){console.log("parent clicked")});
    var child = game.make.sprite(0, 0, 'phaser');
    child.width = 10;
    child.width = 10;
    child.inputEnabled = true;
    child.events.onInputDown.add(function(){console.log("child clicked")});
    //child.input.priorityID = 1;


The problem is that by default the parent catches the click event and does not propagate it to the child. How do I make both child and parent catch the click event?

Link to comment
Share on other sites

I don't see how. onInputDown I always want the ListView down event to fire, because if you then drag it the ListView should scroll. onInputUp events should fire to both the ListView (to stop the drag event) and the display object in the ListView (to execute whatever function is assigned to it).

There are ways to solve this but because ListView is an open source library, the api needs to be simple. It makes sense to me that you can add Display Objects with input event listeners to a ListView and both the ListView events and the ListView's children's events will both fire. 

priorityID let's you choose which event to capture first, but doesn't let you capture multiple events.

Currently my workaround is to capture the ListView's events, and then onInputUp I search for children under the pointer and fire their onInputUp events. It works, but it's ugly in my code.

Link to comment
Share on other sites

  • 8 months later...

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.

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.


  • Recently Browsing   0 members

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