Mouse and stick to move the cursor

I would like to allow the player to move the cursor on the PC screen via the a gamepad stick. DefOS is of course my friend here. But has someone already implemented this? What is a viable solution? Perhaps something like the following approach?

each frame the stick is moved:

  1. get the position of the cursor from the system via defOS
  2. add a movement to this position depending on the input of the stick
  3. set back the position of the cursor via defOS.

Many thanks for any advice!

That should probably work. I haven’t really used DefOS. You could also hide the cursor and implement your own cursor as a game object or GUI node :slight_smile:

1 Like

I will try it and see!

For the moment I have implemented everything using only the gamepad stick with a go: movement, selection and activation of items This is already enough for Switch. Next step I will try to manage the mouse and the PC cursor.

Thanks!

1 Like

In our games, when gamepad input is detected the normal mouse cursor is disabled and a halo like cursor replaces it which then moves around, this one is a GUI node. It’s the solution we use for PC platforms.

3 Likes

@Pkeod Thanks!

But do you use a custom cursor (moved by mouse and gamepad stick) also for windowed mode? Or only for fullscreen?

When there is mouse movement and custom cursor is enabled we enable the custom mouse cursor when it is within the view of the game both windowed and fullscreen. The mouse cursor is not GUI but the custom hardware cursor.

The GUI cursor we use for gamepads to move around. It starts wherever the mouse cursor was last at. When the mouse moves again it is enabled again where it was left at originally. If gamepad gets movement input again it jumps to the new mouse position and so on.

This is just our approach and you can of course do your own approach.

1 Like

@Pkeod Thanks again!

I have indeed implemented a custom cursor using a go. The details may differ somehow but the general structure is similar to the one you described.

  1. I hide the hardware cursor as soon it enters the window and show it as soon as it leaves the window.
  2. If the stick is moved the cursor go is moved and, if the hardware cursor is inside the window, also the hardware cursor is moved accordingly.
  3. If the mouse is inside the window then the cursor go is moved to the position of the mouse.

So I call defOS.get_cursor_pos_view or defOS.set_cursor_pos_view each frame the hardware cursor is inside the window. But I may guess that these are not time-consuming functions on a PC.

This approach seems to work fine in windowed and fullscreen mode.

I hope this topic may be useful to someone else trying to implement this.

Ciao!

2 Likes