Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Reviewed] [Mouse pointer lock] Fixed an issue where extensions did not work on Linux, etc. #1385

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions extensions/reviewed/MousePointerLock.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"name": "MousePointerLock",
"previewIconUrl": "https://resources.gdevelop-app.com/assets/Icons/Line Hero Pack/Master/SVG/Virtual Reality/Virtual Reality_360_rotate_vr_movement.svg",
"shortDescription": "This behavior removes the limit on the distance the mouse can move and hides the cursor.",
"version": "0.1.6",
"version": "0.1.7",
"description": [
"This behavior removes the limit on the distance the mouse can move and hides the cursor.",
"",
Expand All @@ -35,6 +35,8 @@
"Zu55H5hcb9YmZTltIVOTAFDJQyB2"
],
"dependencies": [],
"globalVariables": [],
"sceneVariables": [],
"eventsFunctions": [
{
"fullName": "",
Expand All @@ -49,11 +51,19 @@
"",
"gdjs._MousePointerLockExtension = {};",
"gdjs._MousePointerLockExtension.movement = { x: 0, y: 0 };",
"gdjs._MousePointerLockExtension.retried = false;",
"",
"canvas.addEventListener(\"pointermove\", (e) => {",
" gdjs._MousePointerLockExtension.movement.x += e.movementX || 0;",
" gdjs._MousePointerLockExtension.movement.y += e.movementY || 0;",
"}, false);"
"}, false);",
"",
"document.addEventListener(\"pointerlockerror\", (e) => {",
" if (!gdjs._MousePointerLockExtension.retried) {",
" canvas.requestPointerLock();",
" gdjs._MousePointerLockExtension.retried = true;",
" } ",
"});"
],
"parameterObjects": "",
"useStrict": true,
Expand Down Expand Up @@ -133,13 +143,14 @@
"type": "BuiltinCommonInstructions::JsCode",
"inlineCode": [
"const canvas = runtimeScene.getGame().getRenderer().getCanvas();\r",
"if (canvas.requestPointerLock) {\r",
"if (canvas.requestPointerLock && !document.pointerLockElement) {\r",
" canvas.requestPointerLock({ unadjustedMovement: true });\r",
" gdjs._MousePointerLockExtension.retried = false;\r",
"}"
],
"parameterObjects": "",
"useStrict": true,
"eventsSheetExpanded": false
"eventsSheetExpanded": true
}
],
"parameters": [],
Expand Down