Pointer lock : simple example

I couldn't find a barebone example of this trivial api on the web, so here it is !

Basically, you need to initiate pointer lock mode trough a DOM element that is being clicked. You cant just enter pointer lock mode without user interaction.

Only one element can have "pointer lock rights" at a time, this element is referenced in window.document.pointerLockElement.

There is two events you can listen on :

  • pointerlockchange : when the pointer lock state changes
  • pointerlockerror : when an error occurs during a pointer lock attempt

That's it, now go make the FPS (or something else) you where trying to make !