grinmonk Posted May 24, 2016 Share Posted May 24, 2016 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; sprite.addChild(child); child.inputEnabled = true; child.events.onInputDown.add(function(){console.log("child clicked")}); //child.input.priorityID = 1; } http://phaser.io/sandbox/edit/pfAcVgtC 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 More sharing options...
drhayes Posted May 24, 2016 Share Posted May 24, 2016 I don't think you can. What is this a solution for? If this worked, what would you use it for? Maybe we can work around this if we understood the larger problem better. Link to comment Share on other sites More sharing options...
VitaZheltyakov Posted May 24, 2016 Share Posted May 24, 2016 Use sprite.priorityID Link to comment Share on other sites More sharing options...
drhayes Posted May 25, 2016 Share Posted May 25, 2016 priorityID means you can make the child have priority, but it won't bubble to the parent automatically. You could do it manually at that point, though. Link to comment Share on other sites More sharing options...
mcolman Posted May 26, 2016 Share Posted May 26, 2016 I'm also stuck with this same problem For example this ListView class https://github.com/mattcolman/phaser-list-view You see we can drag the group up and down, but if the children inside the ListView have click events? Currently they're blocked. Link to comment Share on other sites More sharing options...
drhayes Posted May 27, 2016 Share Posted May 27, 2016 mcolman, priorityID would probably solve what you want. Link to comment Share on other sites More sharing options...
mcolman Posted May 29, 2016 Share Posted May 29, 2016 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 More sharing options...
mcolman Posted May 31, 2016 Share Posted May 31, 2016 Rich has answered on slack that it's not possible to propagate click events in Phaser. I definitely feel it would be a good feature. Hopefully Lazer will account for this. I've written a quick function to find the next child under a point with inputEnabled set to true to get around this. Link to comment Share on other sites More sharing options...
shady Posted February 8, 2017 Share Posted February 8, 2017 this is going to be awkward, but i wanna ask what is the predefined function to kill the phaser-list-view? Link to comment Share on other sites More sharing options...
samme Posted February 8, 2017 Share Posted February 8, 2017 Maybe best to target the deepest child with `priorityID` and then propagate the event manually. Link to comment Share on other sites More sharing options...
samme Posted February 8, 2017 Share Posted February 8, 2017 Link to comment Share on other sites More sharing options...
Recommended Posts