kay Posted May 15, 2014 Share Posted May 15, 2014 I use game.input.onDown.add() to detect clicks on the game stage.Now I want to detect clicks on a sprite, but since the previous handler is global, it also fires, when I click on the sprite. The first handler adds a sprite on click, the second one should delete the sprite, when the sprite is clicked. Link to comment Share on other sites More sharing options...
stasuss Posted May 15, 2014 Share Posted May 15, 2014 May be put an invisible sprite on the bottom of the stage and handle its clicks?Or if you have some sort of background image (and I think you should) you can handle its events. kay 1 Link to comment Share on other sites More sharing options...
kay Posted May 15, 2014 Author Share Posted May 15, 2014 How do I create an invisible sprite with the size of the stage? Link to comment Share on other sites More sharing options...
plicatibu Posted May 15, 2014 Share Posted May 15, 2014 You may try the following: attribute a unique name for each of your sprites (say, mysprite = name1, mysprite2 = name2, and so on). in the callback function that handle clicks on sprites you can have something likespriteHandler: function (target) { if (target.name == sprite1.name) { // handle clicks on sprite1 } else if (target.name == sprite1.name) { // handle clicks on sprite2 } else if (target.name == sprite1.name) { // handle clicks on sprite3 }}And in the handle of the stage you could have something likestageHandler: function (target) { if (target.name == sprite1.name) { return; if (target.name == sprite1.name) { return; if (target.name == sprite1.name) { return; } // handle clicks on stage stage} kay 1 Link to comment Share on other sites More sharing options...
stasuss Posted May 15, 2014 Share Posted May 15, 2014 game.add.sprite(0, 0, game.add.bitmapData(800, 480)); kay 1 Link to comment Share on other sites More sharing options...
Recommended Posts