-
Notifications
You must be signed in to change notification settings - Fork 16
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
Comments
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 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 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.. |
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.
|
@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. |
@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. |
Done for Windows at #57 with clipping |
I'll test in next few days unless someone else does before. |
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
The text was updated successfully, but these errors were encountered: