kenray Posted April 18, 2014 Share Posted April 18, 2014 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 More sharing options...
ericjbasti Posted April 18, 2014 Share Posted April 18, 2014 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 More sharing options...
kenray Posted April 19, 2014 Author Share Posted April 19, 2014 Thanks, but how does one utilize this with the game's canvas? And would that even work given that it looks like the canvas element that runs the game fills the browser client area? Link to comment Share on other sites More sharing options...
ericjbasti Posted April 19, 2014 Share Posted April 19, 2014 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 More sharing options...
ericjbasti Posted April 20, 2014 Share Posted April 20, 2014 So Phaser doesn't seem to perform mouseout at all, so here is the file you need to update /input/Mouse.jsand 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 More sharing options...
Recommended Posts