Comments (7)
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).
from defos.
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..
from defos.
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)
from defos.
@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.
from defos.
@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.
from defos.
Done for Windows at #57 with clipping
from defos.
I'll test in next few days unless someone else does before.
from defos.
Related Issues (20)
- Custom OS cursor breaking for macOS since recent update? HOT 12
- Need to change / improve method of setting HTML5 cursor
- Custom cursor images do not work in Microsoft Edge
- Multi monitor / tv setups can create issues with fullscreen mode HOT 2
- FPS cursor lock HOT 2
- Emscripten 1.39 support HOT 2
- hide cursor not working on mac HOT 2
- First input after toggling fullscreen not available on MacOS? HOT 1
- Should defos.on_click() be expanded to cover additional user interaction events? HOT 2
- Cross-platform custom cursors
- allow `clip cursor to game view area` for Linux HOT 1
- Set Window/View Size Before Game Start HOT 2
- Library stops project from building on linux HOT 8
- Changing the window title HOT 3
- Defos for dynamically scaling Defold game window in HTML5? HOT 2
- Toggling fullscreen re-enables window resize if previously disabled (Windows 10)
- Setting initial view size causes error `Could not find '@render' socket` HOT 4
- Updating to Clang 17 in Defold 1.6.2
- Windows 11, using defos.get_view_size() immediatly after defos.set_view_size() return different values. HOT 1
- View size from game.project affects HTML5 canvas size until first window resize
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from defos.