Jump to content

How do I prevent "sticky" drags?


kenray
 Share

Recommended Posts

You can see this effect in the Drag example (http://examples.phaser.io/_site/view_full.html?d=input&f=drag.js&t=drag) - if you mouse down on the keyboard and drag until the pointer is outside the game area, and then release the mouse button and move the pointer back over the game area, you'll see that the keyboard image you dragged is "stuck" to the pointer and moves with it until you click again.

 

Basically I just want the drag to be stopped (as if the user released the mouse button) when the pointer exits the game area, but I can't seem to be able to make that happen...

 

Any idea on how to prevent this from happening? 

Link to comment
Share on other sites

I know this question is relating directly with Phasers implementation, but in general JavaScript terms it needs to fire on mouseout :

canvas.addEventListener("mouseout", mouse_release, false);// add an event to our canvas that triggers our 'mouse_release' function // when the mouse exits. mouse_release is the same function you would want // to fire when the user performs a 'mouseup' action.
Link to comment
Share on other sites

This is where you'll need someone that knows Phaser to help out.

 

Based on the example you could at least try something like this : 

document.getElementById("phaser-example").addEventListener("mouseout", your_function, false);

mouseout not only triggers when leaving the canvas but also when leaving the window. 

Link to comment
Share on other sites

So Phaser doesn't seem to perform mouseout at all, so here is the file you need to update /input/Mouse.js

and here is what needs to be updated... 

Phaser.Mouse.prototype = { ... ... this.game.canvas.addEventListener('mousedown', this._onMouseDown, true); this.game.canvas.addEventListener('mousemove', this._onMouseMove, true); this.game.canvas.addEventListener('mouseup', this._onMouseUp, true); // add this in this.game.canvas.addEventListener('mouseout', this._onMouseUp, true);...
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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