Skip to content

Android: Allow virtual joystick and touch events at the same time - #2951

Merged
riccardobl merged 5 commits into
jMonkeyEngine:masterfrom
terranprog:fix/android-joystick-touch-inputs
Sep 19, 2026
Merged

riccardobl merged 5 commits into
jMonkeyEngine:masterfrom
terranprog:fix/android-joystick-touch-inputs

Conversation

@terranprog

Copy link
Copy Markdown
Contributor

Improve handling of android touch events when virtual joystick is being used.
Previously it was not possible to move using the joystick AND rotate the camera using the touch screen at the same time. You could do one or the other at any one time. If you were using the joystick, touch events would be ignored.
This change fixes that so the user can move forward/back/left/right AND rotate the camera at the same time; just like using a mouse and keyboard.
Disclaimer: this is done using Claude code. I don't have the expertise to understand the changes and what they do. This code should be reviewed by a human who understands this part of the engine.
I found it a big improvement to the UX of my android application so I think it should be seriously considered for inclusion.

…ng used. Previously it was not possible to move using the joystick AND rotate the camera using the touch screen at the same time. You could do one or the other at any one time. This change fixes that so the user can move forward/back/left/right AND rotate the camera at the same time; just like using a mouse and keyboard.
jaime-jmebot

This comment was marked as low quality.

riccardobl and others added 4 commits September 19, 2026 12:01
  pointer taints an in-progress gesture, send a single synthetic
  ACTION_CANCEL and then withhold further events until the gesture ends.
  Previously the detectors were starved mid-stream, which could leave a
  pending long-press or fling that fired later.
- Keep pointers that were hidden at DOWN hidden until their UP/CANCEL, even
  if the joystick drops the capture mid-gesture (setEnabled(false), layout
  resize), so the application never sees a MOVE/UP with no matching DOWN.
- Clear any stale hidden bit on a fresh DOWN for a non-captured pointer, so
  a DOWN that never saw its UP cannot keep a pointer id hidden forever.
- Pass the joystick pointer mask explicitly through
  setJoystickPointerMask() instead of exposing handler state via
  isPointerCapturedByJoystick(), which was only valid during the nested
  dispatch and leaked AndroidInputHandler internals.
- Drop the unrelated keyboardSuppressedAutoJoystick reset on touch DOWN: it
  changes AUTO-mode virtual joystick visibility policy and is not needed to
  use touch and the joystick at the same time.

Co-authored-by: Muse <muse@robot.rblb.it>
When joyInput.onTouch(event) consumes a pointer DOWN or UP, explicitly
preserve that pointer's bit in joystickPointerMask.

This prevents a race condition where joystick captures are cleared
asynchronously (e.g. via setEnabled(false) or layout resizing on another
thread) between joyInput.onTouch() and the subsequent getCapturedPointerMask()
snapshot, which would previously cause the captured DOWN to leak into the
touch pipeline.

Co-authored-by: Gemini 3.8 Flash <gemini@google.com>
Ensure hiddenPointerMask is updated and stale hidden bits are cleared
prior to calling countReportedPointers(event).

On ACTION_DOWN, the mask is reset to 0L to start fresh for a new gesture
stream. On ACTION_POINTER_DOWN, any stale bit for an ordinary pointer is
cleared before computing numPointers, preventing stale hidden state from
corrupting pointer counts and triggering spurious emulated mouse-down events.
Also reset hiddenPointerMask upon ACTION_UP and ACTION_CANCEL.

Co-authored-by: Gemini 3.8 Flash <gemini@google.com>
If a pointer was captured by the virtual joystick during its DOWN event,
subsequent MOVE and UP events should not be processed by IosTouchHandler
if the joystick capture is dropped mid-gesture (e.g. on resize or disable).

Ensure actionMove and actionUp are ignored when the pointer ID is not
present in activePointers, avoiding orphan MOVE and UP events.

Co-authored-by: Gemini 3.8 Flash <gemini@google.com>
@riccardobl
riccardobl merged commit 6bd9e29 into jMonkeyEngine:master Sep 19, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants