phaserlover Posted July 2, 2014 Share Posted July 2, 2014 For example when I'm dragging a map and the mouse is released out of the browser and then I return to the phaser game the map is still dragging because the mouseup event wasn't fired. How to fix this?thanks Link to comment Share on other sites More sharing options...
morosenerd Posted July 2, 2014 Share Posted July 2, 2014 I had this problem too. I had no idea how to fix it within Phaser, so I just hacked a workaround by adding my own listener for onMouseOver, something like this: this.div = document.getElementById('game');this.div.onmouseover = this.onMouseOver; and then I had a function: onMouseOver: function(e) { if (e.buttons >= 0) { //mouse returned with the button still pressed, continue dragging } else { //mouse returned with the button released, add code to stop dragging }} Link to comment Share on other sites More sharing options...
Youle Posted July 3, 2014 Share Posted July 3, 2014 I had this problem too. I had no idea how to fix it within Phaser, so I just hacked a workaround by adding my own listener for onMouseOver, something like this:this.div = document.getElementById('game');this.div.onmouseover = this.onMouseOver;Can't you just :myDiv.onmouseout = function(){ // Stop dragging }can you ? Link to comment Share on other sites More sharing options...
Youle Posted July 3, 2014 Share Posted July 3, 2014 In Game Desig logic, you should cancel the action, I think that the player would prefer restart dragging action than the object going to a non desired place because of his non precise mouse Link to comment Share on other sites More sharing options...
ianmcgregor Posted July 3, 2014 Share Posted July 3, 2014 I have a snippet for catching when the mouse leaves the browser. I don't know if it solves your specific problem, but here goes: function mouseLeftWindow(fn, context) { document.addEventListener('mouseout', function(e) { var from = e.relatedTarget || e.toElement; if (!from || from.nodeName === 'HTML') { fn.call(context || this); } }); } Link to comment Share on other sites More sharing options...
morosenerd Posted July 3, 2014 Share Posted July 3, 2014 In Game Desig logic, you should cancel the action, I think that the player would prefer restart dragging action than the object going to a non desired place because of his non precise mouse In my case, cancelling was undesired. In that particular game, it was much better to allow to continue dragging even after accidentally hitting the border. It is game-specific though. Your code will ofc work. Link to comment Share on other sites More sharing options...
Youle Posted July 3, 2014 Share Posted July 3, 2014 You're actually right morosenerd, last time I needed that sort of situation was for a Tower Defense (I only thought around it ^^') Link to comment Share on other sites More sharing options...
Recommended Posts