How to translate the mouse cursor to the other side of the screen?

HI guys !
What can I do to move/translate/teleport :grinning_face_with_smiling_eyes: the mouse cursor to the other side of the screen?
I want to create an infinite loop, when cursor arrives to the end of screen it would keep continuously moving reappearing in the other side, something like in blender editorā€¦
Hereunder a bit of pseudo code (that does not work, of course):

	if  action.x > 1918 then
		action.x = 3
	elseif action.x < 3 then
		action.x = 1918
	end

The snippet of code above will not actually move the cursor. It will merely change the positional information about the cursor which you received from the system. If you want to physically move the mouse cursor you can do so using DefOS:

defos.set_cursor_pos(x, y) -- In screen coordinates
defos.set_cursor_pos_view(x, y) -- In game view coordinates
2 Likes

@britzl In fact I donā€™t need the cursor to be visible, I need only that the positional information keeps running as I keep moving the mouse, but it stops when the cursor reaches the border of the screen/window.
Is there any other way of doing it? I mean, to keep compatibility with HTML5.
Thanks a lot!

Usually, one locks the hardware cursor in the middle of the screen, and hides it.
That way it will always produce delta values.
DefOS should be able to help with this.

Youā€™ll then use ā€œaction.dxā€ and ā€œaction.dyā€ to in your scripts.

1 Like

I believe getting the mouse position when ā€œhoveringā€ is limited to the canvas size of the app.

Going full-screen would work, but that may not be possible. I seem to remember the mouse coordinates are still available when dragging (whilst keeping the mouse button down). If so, maybe that could help.

What are you trying to do?

1 Like

The only problem with this approach is the lack of compatibility with HTML5

Yes, it is exactly what I want to doā€¦
But if possible, not dragging, kind of like in Doom3 when we set the mouse to strafe/lookā€¦
I am able to make the player complete two turns around himself only hovering, but I am trying to do a third person ā€œflying shooterā€ and it would be nice if the loop would be infiniteā€¦

IIrc, you should be able to hide the cursor there too?

1 Like

Isnā€™t this exactly what defos.set_cursor_locked() does? Did you read the readme? A few people have done this recently with 3D projects on HTML5, you should take a look at Scene3D and Operator.

3 Likes

Itā€™s my mistake, I think it works also in HTML5.
Thank you.

My mistake, I thought it was incompatible with HTML 5.
And I will look at Scene3D and Operator.
Thank you!

2 Likes

High Guys,
Iā€™ve implemented the defold-pointer-lock,
and it works fine while the cursor is visible:
mars_caves_with_cursor

,but the input from keyboard is not detectable when the cursor is hidden.
Therefore the player does not move when the arrows ( throttle/breaks) are pressed, it just turns around himself with the mouse movement.
Do you have any clues?
mars_caves_no_cursor

3 Likes

Iā€™ve found it in pointer.lua lines 16-18:

    if not M.locked or not M.cursor_visible then
        action_id = nil
    end

Iā€™ve changed
ā€œor not M.cursor_visibleā€
by
ā€œor M.cursor_visibleā€
and it behaves correctly for meā€¦ :wink:

1 Like