You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-06 12:20:30 +00:00
[HTML5] Implement Pointer Lock API in JS library.
Removes more emscripten HTML5 library dependencies.
This commit is contained in:
@@ -376,6 +376,20 @@ const GodotDisplayCursor = {
|
||||
delete GodotDisplayCursor.cursors[key];
|
||||
});
|
||||
},
|
||||
lockPointer: function () {
|
||||
const canvas = GodotConfig.canvas;
|
||||
if (canvas.requestPointerLock) {
|
||||
canvas.requestPointerLock();
|
||||
}
|
||||
},
|
||||
releasePointer: function () {
|
||||
if (document.exitPointerLock) {
|
||||
document.exitPointerLock();
|
||||
}
|
||||
},
|
||||
isPointerLocked: function () {
|
||||
return document.pointerLockElement === GodotConfig.canvas;
|
||||
},
|
||||
},
|
||||
};
|
||||
mergeInto(LibraryManager.library, GodotDisplayCursor);
|
||||
@@ -850,6 +864,20 @@ const GodotDisplay = {
|
||||
}
|
||||
},
|
||||
|
||||
godot_js_display_cursor_lock_set__sig: 'vi',
|
||||
godot_js_display_cursor_lock_set: function (p_lock) {
|
||||
if (p_lock) {
|
||||
GodotDisplayCursor.lockPointer();
|
||||
} else {
|
||||
GodotDisplayCursor.releasePointer();
|
||||
}
|
||||
},
|
||||
|
||||
godot_js_display_cursor_is_locked__sig: 'i',
|
||||
godot_js_display_cursor_is_locked: function () {
|
||||
return GodotDisplayCursor.isPointerLocked() ? 1 : 0;
|
||||
},
|
||||
|
||||
/*
|
||||
* Listeners
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user