Jump to content

Disable inputUP firing when holded pointer goes out of canvas


Lizard
 Share

Recommended Posts

I don't think you can disable it directly, as there is no way for the game to find out where the pointer moved once out of the canvas. Someone can correct me if wrong :).

One solution I can think of is that upon calling onUp() to check whether the mouse is still within the range of the game.

 

For the example that would mean:

game.input.mousePointer.x should be > 0 and < 800.
game.input.mousePointer.y should be > 0 and < 600.

Link to comment
Share on other sites

Yeah, you probably should. Most GUI systems work like that, i.e. they let you click in the button, move outside the bounds of the button, release the mouse and it won't click the button. I don't remember the *exact* call, but you have to re-check that your pointer is still inside the bounds of whatever it is that's clickable. "sprite.input.checkboundsSprite" maybe? I forget.

Link to comment
Share on other sites

For checking is pointer still on sprite/button you can use third argument of onInputUp.

It is sent three arguments:
{any} The Game Object that received the event.
{Phaser.Pointer} The Phaser.Pointer object that caused the event.
{boolean} isOver - Is the Pointer still over the Game Object?

But in case when sprite near canvas border it could trigger wrong onInputUp event, when pointer with holded button will move out of canvas from sprite.

It you will look at pointer coords at this moment it will be inside canvas and third argument of onInputUp will be true.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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