-
Notifications
You must be signed in to change notification settings - Fork 0
Add touch event listeners for mobile movement tracking in speed modifier component #18
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,17 +32,21 @@ const movementSpeedModifierComponent = { | |
| this.currentAppliedMultiplier = 1; // Set to 1 initially as the boost needs to be triggered | ||
| this.axisX = 0; | ||
| this.axisY = 0; | ||
| this.touchCount = 0; | ||
| this.timeSinceLastLinePattern = 0; | ||
| // Bind handlers to this component instance, and store the references so listeners can be removed later | ||
| this.onThumbstickDown = this.onThumbstickDown.bind(this); | ||
| this.onAxisMove = this.onAxisMove.bind(this); | ||
| this.onKeyDown = this.onKeyDown.bind(this); | ||
| this.onKeyUp = this.onKeyUp.bind(this); | ||
| this.onWindowBlur = this.onWindowBlur.bind(this); | ||
| this.onTouchStart = this.onTouchStart.bind(this); | ||
| this.onTouchEnd = this.onTouchEnd.bind(this); | ||
| // Set up input listeners | ||
| this.leftControllerEl = this.data.leftController; | ||
| this.addLeftControllerListeners(); | ||
| this.addKeyboardListeners(); | ||
| this.addTouchListeners(); | ||
| // Create the speed line container and line elements | ||
| this.lineContainer = null; | ||
| this.lineElements = []; | ||
|
|
@@ -97,6 +101,7 @@ const movementSpeedModifierComponent = { | |
| remove: function () { | ||
| this.removeLeftControllerListeners(); | ||
| this.removeKeyboardListeners(); | ||
| this.removeTouchListeners(); | ||
| this.resetSpeeds(); | ||
| this.removeSpeedLines(); | ||
| }, | ||
|
|
@@ -145,6 +150,28 @@ const movementSpeedModifierComponent = { | |
| window.removeEventListener("blur", this.onWindowBlur); | ||
| }, | ||
|
|
||
| /** | ||
| * Add touch listeners | ||
| * | ||
| * Adds touch listeners to track the number of fingers on the screen for mobile movement. | ||
| */ | ||
| addTouchListeners: function () { | ||
| window.addEventListener("touchstart", this.onTouchStart); | ||
| window.addEventListener("touchend", this.onTouchEnd); | ||
| window.addEventListener("touchcancel", this.onTouchEnd); | ||
| }, | ||
|
|
||
| /** | ||
| * Remove touch listeners | ||
| * | ||
| * Removes the touch listeners used for mobile movement tracking. | ||
| */ | ||
| removeTouchListeners: function () { | ||
| window.removeEventListener("touchstart", this.onTouchStart); | ||
| window.removeEventListener("touchend", this.onTouchEnd); | ||
| window.removeEventListener("touchcancel", this.onTouchEnd); | ||
| }, | ||
|
Comment on lines
+169
to
+173
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not applicable. |
||
|
|
||
| /** | ||
| * Thumbstick down handler | ||
| * | ||
|
|
@@ -233,6 +260,30 @@ const movementSpeedModifierComponent = { | |
| this.applySpeedMultiplier(); | ||
| }, | ||
|
|
||
| /** | ||
| * Touch start handler | ||
| * | ||
| * Tracks the number of fingers on the screen to detect forward or backward movement on mobile. | ||
| * | ||
| * @param {TouchEvent} event The touch event. | ||
| */ | ||
| onTouchStart: function (event) { | ||
| this.touchCount = event.touches.length; | ||
| this.syncSpeedLinesVisibility(); | ||
| }, | ||
|
Comment on lines
+270
to
+273
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
|
|
||
| /** | ||
| * Touch end handler | ||
| * | ||
| * Tracks the number of fingers on the screen to detect when movement stops on mobile. | ||
| * | ||
| * @param {TouchEvent} event The touch event. | ||
| */ | ||
| onTouchEnd: function (event) { | ||
| this.touchCount = event.touches.length; | ||
| this.syncSpeedLinesVisibility(); | ||
| }, | ||
|
|
||
| /** | ||
| * Is joystick forward | ||
| * | ||
|
|
@@ -287,7 +338,8 @@ const movementSpeedModifierComponent = { | |
| const keyboardMovingForward = this.keyboardForwardActive; | ||
| const joystickMovingForward = this.isJoystickForward(); | ||
| const armSwingMovingForward = armSwingMovement && armSwingMovement.moving && !armSwingMovement.reverseHeld; | ||
| return keyboardMovingForward || joystickMovingForward || armSwingMovingForward; | ||
| const touchMovingForward = this.touchCount === 1; // 1 finger = forward, 2 = backward | ||
|
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's the |
||
| return keyboardMovingForward || joystickMovingForward || armSwingMovingForward || touchMovingForward; | ||
|
Comment on lines
+341
to
+342
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't need to check |
||
| }, | ||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and there were no warnings. Scroll performance is not applicable for A-Frame scenes.