Jump to content

input.onUp dispatched after mouseout event


Zeterain
 Share

Recommended Posts

I noticed that input.onUp is dispatched when the canvas event mouseout is fired. Phaser version 2.4.6.

When mouseout is triggered on the canvas element, Phaser.Mouse.onMouseOut is called, which stops the mousePointer. Phaser.Pointer.stop then dispatches input.onUp. This is confusing because onUp can be dispatched even when the pointer is not actually released, but rather when the pointer simply leaves the canvas.

Phaser.Pointer.Stop is also called when an active pointer leaves a touchscreen. It would make sense for onUp to be dispatched in this case because you can't tell whether the pointer was released at the edge of the screen or dragged off the screen completely. It doesn't make sense for a pointer that was never down to begin with.

Thoughts? Is this an issue, or is this intentional?

*Note: You can write around this strangeness without a problem. You are given the DOM event that triggered a Phaser event, so you can check to see if the event was a mouseout before taking action. I just want to make sure everything is behaving the way it should before writing around a problem.

 

An example of a game that demonstrates this behavior. Note that the console will log the type of DOM event that triggered the onUp event.

var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { create: create });

function create() {

    game.input.onUp.add(function(pointer, event) {
        console.log("Up!", event.type);
    });

}

 

Link to comment
Share on other sites

  • 2 weeks later...

Got the same "problem". You can also check if the pointer is inside the game area:

game.input.onUp.add(function (pointer) {
  if (!pointer.withinGame) { return; }
  // ...
});

In my case, I'm trying to check for swipe gestures, so I think receiving an "onUp" signal when the pointer goes off the game area is desired. What I did to "fix" it from being fired even when no pointer was pressed is to register a handler for "onDown" signal and track only a specific pointer ID:

game.input.onDown.add(function (pointer) {
  if (!pointer.withinGame) { return; }
  this.trackingPointer = pointer.id;
}, this);

game.input.onUp.add(function (pointer) {
  if (this.trackingPointer !== pointer.id) { return; }
  // ...
  delete this.trackingPointer;
}, this);

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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