ecj2 / momo

[NOT MAINTAINED / ABANDONED] A simple 2D game-making library written in JavaScript.
MIT License
1 stars 0 forks source link

Momo.lockMouse() fails in Firefox 71.0 #33

Closed ecj2 closed 4 years ago

ecj2 commented 4 years ago

This code:

if (Momo.isMouseButtonPressed("left")) {

  Momo.lockMouse();
}

Produces the following console message in Firefox 71.0:

Request for pointer lock was denied because Element.requestPointerLock() was not called from inside a short running user-generated event handler, and the document is not in full screen.

It works without issue in Chrome 79.

Using Momo.getCanvas().addEventListener("click", () => {Momo.lockMouse();}); works instead. The internals of Momo.lockMouse() should be changed to reflect this.

ecj2 commented 4 years ago

This can not be fixed. While Momo.lockMouse() can be called under any condition at any time in Chrome, it can only be called from within a custom event listener in Firefox. The latter is by design of Mozilla.