Mouse position, transformed to canvas pixels.
All currently held buttons.
whether the pointer is visible.
Check if button is held. Button 1 = left, 2 = middle, 3 = right.
True when pointer is locked to canvas.
Enable/disable pointer lock (capture).
For more fine-grained control, use setMode which also documents behaviors more thoroughly.
Only applicable in capture mode -- sets the position of the emulated mouse.
Set the current cursor mode.
Consider setting scrollBlock to false (default is true) if you want
your element to blend into the webpage for freer scrolling.
{
lock: false,
visible: true, // disable to hide cursor.
scrollBlock: true, // disable scroll while hovering canvas. Default: true
}
In locked mode, the cursor cannot escape the canvas.
It also becomes invisible.
However, it can move infinitely, sensitivity can be controlled,
and the emulated cursor (in pos of index.LikeHandlers.mousemoved) can be freely repositioned.
{
lock: true,
speed: 1.0, // mouse sensitivity
}
Avoid binding the ESC key in captured mode. This will exit the capture and
reset mode to default.
pos vs deltaEvent index.LikeHandlers.mousemoved passes both pos and delta args.
Though the emulated cursor in locked mode
(locked mode doesn't natively track absolute position)
may be stuck on canvas edges, the delta field always
represents mouse movement, even against edges.
LIKE's mouse wrapper.
Mouse coordinates are scaled for convenience. For example call:
and your game will now be 240x160 pixels.
Your mouse coords will stay within the rectangle
[0, 0]and[240, 160].If you intend to allow scrolling on your page while the mouse is above the game, use:
Capture
Some games benefit from capture aka pointer lock. Call
to use capture, and now the mouse is locked to the game.
When you enter capture, the mouse
posbecomes virtual, bounded to canvas edges, plus controlled via the speed setting and teleport-able via setCapturedPos.When you exit capture, the mouse will be in the same spot the capture was started in.
Note that your mode settings from non-capture mode are preserved in capture mode and vice-versa.