Jump to content

How to detect a stage-click only when no sprite is between cursor and stage?


kay
 Share

Recommended Posts

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

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 like

spriteHandler: 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 like

stageHandler: 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}
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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