Mouse management in JavaScript games

Posted by Jakob on Stack Overflow See other posts from Stack Overflow or by Jakob
Published on 2010-04-11T09:37:44Z Indexed on 2010/04/11 9:43 UTC
Read the original article Hit count: 190

Im using JavaScript, the HTML5 canvas-element and WebGL to make a simple 3D-game in first person view for fun.

Ideally, I would like to control my movement by using the keyboard to move and the mouse to look around, like you usually do in FPS-games. As you probably understand, there are some limits to this in the browser, since the mouse cant be captured:

  • When using the onmousemove event, no further movement will be detected when the mouse pointer reaches the border of my screen (which means that I wont be able to run in a circle for example)
  • Seeing the mouse move across the screen is not the end of the world, but it is a little annoying

From what I know, it's impossible to hide the mouse as well as setting it's position in JavaScript. Hence, my question is this:

If we cant to those things, what can we do in order to get close to the desktop gaming experience when it comes to the mouse in the browser?

And I mean right now, using current APIs. Not "what could be changed in some standard to make life easier". Also, I realize that I could use the keyboard to look around, but then we're back in 1995 when Quake were actually played like that. And of course I know that it would be easier to write a desktop application or use Flash at least, but Im trying to push JavaScript's limits here.

Apart from those things, what are your suggestions? Any kind of reference, existing game, crazy idea, hack or even browser specific solution would be appreciated.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about game-development