Skip to content

Virtual/on-screen joystick support#2803

Merged
yaRnMcDonuts merged 7 commits into
jMonkeyEngine:masterfrom
riccardobl:onscreengamepad
May 26, 2026
Merged

Virtual/on-screen joystick support#2803
yaRnMcDonuts merged 7 commits into
jMonkeyEngine:masterfrom
riccardobl:onscreengamepad

Conversation

@riccardobl
Copy link
Copy Markdown
Member

@riccardobl riccardobl commented May 24, 2026

This PR makes joystick support available everywhere by adding an on-screen virtual joystick integrated directly into the input backend.

The advantage of this approach is that a jME application sees the virtual joystick just like any other Xbox-style joystick supported by jME. No special handling is needed: applications can use the usual joystick bindings.

The controls are rendered as spatials attached to the node passed to the joystick update method. When using SimpleApplication, this is already handled correctly and the controls end up in the guiNode, so normal jME apps do not need any additional setup.

xbox layout

image

dynamic layout

image

Since it now conflicts with this, the AndroidSensorJoyInput (that is used to simulate android joysticks using accelerometer), is now disabled by default and gated behind the UseAndroidSensorJoystick app setting.

Other changes to AppSettings:

  • DisableJoysticks is now off by default, meaning gamepads are always supported when available
  • VirtualJoystick can be used to set the virtual joystick mode , defaults to VIRTUAL_JOYSTICK_AUTO
  • VirtualJoystickDefaultLayout can be used to set the virtual joystick layout, defaults to VIRTUAL_JOYSTICK_LAYOUT_DYNAMIC

Default settings should just work as expected in most apps, but these appsettings allow some customization:

modes

  • VIRTUAL_JOYSTICK_DISABLED will never show the virtual joystick
  • VIRTUAL_JOYSTICK_ENABLED will always show the virtual joystick
  • VIRTUAL_JOYSTICK_AUTO will automatically display the virtual joystick on mobile, if there is at least one joystick bind registered by the app, and if there is not an hardware joystick connected

default layouts

  • VIRTUAL_JOYSTICK_LAYOUT_XBOX will show a full xbox-like layout
  • VIRTUAL_JOYSTICK_LAYOUT_DYNAMIC will only show the buttons used by the app

advanced usage

it is possible to set custom layouts and tweak the virtual joystick even more, by accessing the VirtualJoystick object, that is retrievable via InputManager.getJoysticks()

@riccardobl riccardobl changed the title Virtual joystick support Virtual/on-screen joystick support May 24, 2026
gemini-code-assist[bot]

This comment was marked as outdated.

@riccardobl riccardobl force-pushed the onscreengamepad branch 2 times, most recently from 1c6fb91 to b81c49d Compare May 25, 2026 09:48
@riccardobl riccardobl marked this pull request as ready for review May 25, 2026 12:02
@riccardobl

This comment was marked as outdated.

gemini-code-assist[bot]

This comment was marked as outdated.

@riccardobl

This comment was marked as outdated.

gemini-code-assist[bot]

This comment was marked as outdated.

@riccardobl

This comment was marked as outdated.

@github-actions

This comment was marked as outdated.

gemini-code-assist[bot]

This comment was marked as outdated.

@yaRnMcDonuts yaRnMcDonuts added this to the v3.10.0 milestone May 26, 2026
@yaRnMcDonuts yaRnMcDonuts merged commit 1a32b66 into jMonkeyEngine:master May 26, 2026
10 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.

2 participants