Request pointer lock when project started

This commit is contained in:
Thomas Weber committed 2021-08-10 20:54:30 -05:00
1 parent 12157358a3
commit 7b79754cc0
1 file changed
+9 -3
+9 -3
View File
@@ -3,7 +3,7 @@ const run = (scaffolding) => {
const vm = scaffolding.vm;
const mouse = vm.runtime.ioDevices.mouse;
let isLocked = false;
const postMouseData = (e, isDown) => {
const {movementX, movementY} = e;
const {width, height} = scaffolding.layersRect;
@@ -45,14 +45,20 @@ const run = (scaffolding) => {
postMouseData(e);
}
}, true);
scaffolding.addEventListener('PROJECT_RUN_START', () => {
if (!isLocked) {
canvas.requestPointerLock();
}
});
document.addEventListener('pointerlockchange', () => {
isLocked = document.pointerLockElement === canvas;
});
document.addEventListener('pointerlockerror', (e) => {
console.error('Pointer lock error', e);
});
const oldStep = vm.runtime._step;
vm.runtime._step = function (...args) {
const ret = oldStep.call(this, ...args);