Jump to content


Photo

Mouse Extension


  • Please log in to reply
5 replies to this topic

#1 Schalk

Schalk

    GMC Member

  • GMC Member
  • 487 posts
  • Version:GM:HTML5

Posted 17 October 2011 - 09:23 PM

Description
Provides mouse input outside of the game canvas.

Functions
window_mouse_x() - x coordinate of mouse relative to the canvas
window_mouse_y() - y coordinate of mouse relative to the canvas

display_mouse_x() - x coordinate of mouse on the browser
display_mouse_y() - y coordinate of mouse on the browser

Live Example
http://syntaxgames.c...amemaker/mouse/

Links
http://syntaxgames.c...mouse/Mouse.zip (direct)
http://www.crocko.co...1D5A8/Mouse.zip (mirror)

How To Use
Because GML doesn't currently work for extensions in Game Maker HTML5, I have included Mouse.gex and a Mouse.gml. The extension contains the Javascript for display_mouse functions and the GML contains the scripts for the window_mouse. Just add those to your project and you're set to go.

Compatibility

We did used to do this, but the problem is if you do capture input outside of the canvas the whole web page suffers. You can no longer scroll pages on tablets, and some input doesn't go through to the underlying page, which makes it unsuitable for using in a web environment.

This forced us to only capture "canvas" events. JavaScript and Canvas does have some nasty - and stupid - limitations. We will keep looking for an answer, but until we get one that works across the board, we're stuck with what we have.

Sorry.


License
Feel free to use and abuse as you wish. Credit goes to http://javascript.in...oordinates.html for the Javascript.

EDIT: Also, please note that when using an iframe, I don't believe an iframe can capture any mouse input outside of that frame. (Please do correct me if i'm wrong).

Edited by Schalk, 18 October 2011 - 10:11 AM.

  • 1

#2 cotycrg

cotycrg

    GMC Member

  • GMC Member
  • 867 posts
  • Version:GM:Studio

Posted 18 October 2011 - 01:03 AM

Ahhhh. This would be great, but it's lacking the most important thing missing here, mouse_x and mouse_y variables relative to the canvas! (Also, to bad that it doesn't work outside of the actual browser window, as well)
  • 0

#3 Cycododge

Cycododge

    GMC Member

  • GMC Member
  • 230 posts
  • Version:GM:Studio

Posted 18 October 2011 - 01:09 AM

It does show it relative to the canvas. window_mouse_x().
  • 1

#4 Schalk

Schalk

    GMC Member

  • GMC Member
  • 487 posts
  • Version:GM:HTML5

Posted 18 October 2011 - 01:10 AM

Ahhhh. This would be great, but it's lacking the most important thing missing here, mouse_x and mouse_y variables relative to the canvas! (Also, to bad that it doesn't work outside of the actual browser window, as well)

No, it has those:

window_mouse_x() - x coordinate of mouse relative to the canvas
window_mouse_y() - y coordinate of mouse relative to the canvas


Yeah that's a browser/javascript limitation. As you can imagine, if it was possible to track the mouse anywhere on the screen, that will raise security alarms.
  • 0

#5 autukill

autukill

    GMC Member

  • GMC Member
  • 14 posts
  • Version:GM:Studio

Posted 26 February 2012 - 02:18 PM

:biggrin:

I very want to study JS to GM
I have read【 http://gmc.yoyogames.com/index.php?showtopic=520070】,it is easy!

I need your help:
js code:
document.onmousemove = getMouseXY;
function display_mouse_x()
{ 
	return   event.clientX + document.body.scrollLeft;
} 
function display_mouse_y()
{
	return  event.clientY + document.body.scrollTop;		
}  
why not run?

Edited by autukill, 26 February 2012 - 02:21 PM.

  • 0

#6 MartinPiper

MartinPiper

    GMC Member

  • GMC Member
  • 36 posts
  • Version:GM:Studio

Posted 17 December 2013 - 04:44 PM

Hey ! The script looks really good and useful. But at the same time, both the download links are not working for me. Could you please re-upload the extension ? Thank you :)


  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users