Skip to content
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

Lock/unlock mouse cursor to window #32

Closed
subsoap opened this issue Nov 8, 2017 · 7 comments
Closed

Lock/unlock mouse cursor to window #32

subsoap opened this issue Nov 8, 2017 · 7 comments

Comments

@subsoap
Copy link
Owner

subsoap commented Nov 8, 2017

todo

https://msdn.microsoft.com/en-us/library/windows/desktop/ms648383(v=vs.85).aspx

https://github.com/d954mas/Defold-lock-cursor/blob/master/lock/extension/src/LockMouse.cpp

@subsoap
Copy link
Owner Author

subsoap commented Nov 10, 2017

Locking cursor to center of the window, used in FPS shooters where you want the user to be able to continuously turn around with the mouse. mouse dx and mouse dy are used to get rotation. Generally you want to show a graphic which is centered in the screen and hide the mouse cursor. If you don't hide the mouse cursor as you turn around you'll still see the mouse dx/dy distances from center which is weird.

is_cursor_locked
lock_cursor
unlock_cursor

Clips the cursor to the borders of the current window so that it cannot exit the window bounds. Useful in games like Diablo where you might want to play in window mode with lots of fast clicking and not accidentally click outside of the game window.

is_cursor_clipped
clip_cursor
unclip_cursor

Generally if playing in window mode if the user presses ESC you want to open a pause overlay menu of some kind and unclip the cursor so that it can leave the window bounds.

For FPS game you want similar behavior where pressing ESC displays the normal cursor again which is allowed to move around the window freely while the overlay is visible..

@rgrams
Copy link

rgrams commented Nov 11, 2017

The way d954mas's Lock extension works is it just sets the mouse position back to some preset position every time you call the function and reports dx and dy. So all you really need is a set_mouse_position function. You can get dx and dy from input events normally, and DefOS already has the show/hide cursor functions.

"Capture"ing the mouse to a window should be done with this I think? (no, I was wrong)

@subsoap
Copy link
Owner Author

subsoap commented Jan 8, 2018

@rgrams Should test making a first person shooter type camera with Rendercam. Hide mouse cursor, always set mouse x,y to center of screen, use mouse dx/dy to rotate fps camera.

@rgrams
Copy link

rgrams commented Jan 8, 2018

@subsoap I have. It was pretty darn easy. I used d954mas's Lock extension from his Save Shelter game for the native extension part. (it's Windows & HTML only) If DefOS gets a 'set mouse position' function then I would use that instead.

@chaosddp
Copy link
Collaborator

Done for Windows at #57 with clipping

@subsoap
Copy link
Owner Author

subsoap commented Jan 28, 2018

I'll test in next few days unless someone else does before.

@dapetcu21
Copy link
Collaborator

I think we can close this, as it’s been implemented for all platforms in #57 and #60 (minus clipping for HTML5, but as far as I know that’s not possible).

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

No branches or pull requests

4 participants