marcgfx Posted May 14, 2017 Share Posted May 14, 2017 I am using NW.js for my game Devader (http://falkenbrew.com) and if the mouse leaves the window/application it's possible for the player to lose focus on the game, what can be very annoying. I can't come up with a solution. I need the cursor to be shown, but I don't want the cursor to exit the screen. A possible solution might be to use pointer lock (http://www.smartjava.org/content/html5-use-pointer-lock-api-restrict-mouse-movement-element) but it will be awkward to handle and it won't be possible to use the GUI I have so far. So ... maybe I could hack it in, but I really don't like the sound of it. Has anyone dealt with this problem before? Quote Link to comment Share on other sites More sharing options...
Nesh108 Posted May 15, 2017 Share Posted May 15, 2017 Yeah, pointer lock + cursor within the game is the solution. You are a bit stuck there as you can't really control the user's mouse from a page (and thanks for that!). So, keep it like that until you are ready to improve the GUI Quote Link to comment Share on other sites More sharing options...
mattstyles Posted May 15, 2017 Share Posted May 15, 2017 It would be mega mega annoying for users playing in a window to have their mouse effectively taken away from them, the pointer lock hack works because you still need to ask for permission from a user to hijack their mouse but a different solution would be to enforce fullscreen playing, that way you do nothing, the user simply cant make their mouse exit the screen as the game fills it. Quote Link to comment Share on other sites More sharing options...
imerso Posted May 15, 2017 Share Posted May 15, 2017 1 hour ago, mattstyles said: ... a different solution would be to enforce fullscreen playing, that way you do nothing, the user simply cant make their mouse exit the screen as the game fills it. Unless the user has multi-monitor, then he still can click in the other screen and lose focus. I believe that there is no perfect solution yet, but what I do is keep a flag knowing if the game is in fullscreen or not. If not, then when the user clicks on the screen for any reason, then I switch to fullscreen and lock mouse cursor. If I need a pointer inside the game, then I use my own in-game pointer, not the default pointer which could leave the game screen. If he presses ESC leaving fullscreen, ok, he gets his pointer back, but to continue playing he must click back (and then I switch to fullscreen and lock cursor again). Quote Link to comment Share on other sites More sharing options...
marcgfx Posted May 16, 2017 Author Share Posted May 16, 2017 The multi-screen is the problem. I already start the game in full-screen with nw.js but I can still click outside the window. I guess pointer lock api is the solution, thanks guys! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.