Clamp mouse to window?
by Jerrod Putman · in Torque Game Builder · 11/03/2007 (12:13 am) · 10 replies
I've been doing searches of the site for well over an hour, and I couldn't find any information that really addressed this issue (or worked).
Anyways, I'm trying to ensure that the mouse cursor doesn't leave the window, so that in a mouse controlled game, players don't accidentally move the cursor outside of the window and start clicking on Word documents or whatever. I've tried using cursorOff() and a host of other things, and regardless of what the cursor does inside the window, I am still able to leave the window and click on other things.
Now, it's entirely possible that this feature isn't built into TGB, and I'm supposed to handle the mouse positioning myself. That would be fine. I just want to know how to do this the "proper" way.
Thanks for any help you can give me.
Anyways, I'm trying to ensure that the mouse cursor doesn't leave the window, so that in a mouse controlled game, players don't accidentally move the cursor outside of the window and start clicking on Word documents or whatever. I've tried using cursorOff() and a host of other things, and regardless of what the cursor does inside the window, I am still able to leave the window and click on other things.
Now, it's entirely possible that this feature isn't built into TGB, and I'm supposed to handle the mouse positioning myself. That would be fine. I just want to know how to do this the "proper" way.
Thanks for any help you can give me.
#2
However, if you are going to keep the mouse inside your game window, just use full screen instead. The arguments against full screen, that it keeps people from being able to switch to other apps while playing your game, apply to the method that you want to use as well.
If you aren't going to let them click their Word document, don't show it to them.
Greg
11/03/2007 (3:45 am)
You can manually check with a timer if the mouse is outside the bounds of your scenewindow and put it back with setMousePosition.However, if you are going to keep the mouse inside your game window, just use full screen instead. The arguments against full screen, that it keeps people from being able to switch to other apps while playing your game, apply to the method that you want to use as well.
If you aren't going to let them click their Word document, don't show it to them.
Greg
#3
Well, if there's no automatic way, I'll do it manually (might not be too hard).
11/03/2007 (4:27 am)
Quote:use full screen instead.But on dual screen it doesn't prevent going to the other screen (and I'm on dual screen).
Well, if there's no automatic way, I'll do it manually (might not be too hard).
#4
11/03/2007 (6:22 pm)
FYI people tend to hate games that do this. The whole point of "windowed mode" is being able to surf the net, chat or read word documents while playing a game. You should really just pause the game when they leave the window, if anything.
#5
In any case, it seems that the short of it is that this will have to be done manually. Not a problem. I just wanted to make sure that I wasn't missing some painfully obvious feature of the engine.
11/03/2007 (10:51 pm)
Well, the cursor isn't going to be visible on-screen anyways, and I'm doing some action-oriented gameplay built around the mouse. So being in the heat of gameplay and accidentally clicking or moving outside the window isn't necessarily what I want. And yes, I could just force full-screen at all times, but I'd like to be able to give the option of windowed mode. And again, I develop in windowed mode so I can debug, so I'd like it for my own sanity.In any case, it seems that the short of it is that this will have to be done manually. Not a problem. I just wanted to make sure that I wasn't missing some painfully obvious feature of the engine.
#6
If there is any kind of 'ettiquette rule' it is this:
If a game requires complete and total mouse or trackpad control in realtime, like what you are describing, than full screen is appropriate and correct.
If a game does NOT require such complete and total of the mouse in realtime, then full screen is innappropriate and rude.
To illustrate, a Suduko game that forces the user into full screen is annoying; it prevents the user from multitasking, checking email, etc.
A Marble Blast kind of game, where the mouse controls the rolling marble, that plays in a window and NOT full screen is equally annoying. When the mouse leaves the window and you lose control, it takes you out of the realtime experience and is frustrating.
The game you are describing suggests that full screen is the most appropriate option. Hiding the cursor in windowed mode is not recommended. I understand developing in windowed mode, but if your final game is going to have a hidden mouse with realtime mouse control, full screen is the best option for the user and you.
A nice thing to do with full screen games, in my opinon, is to window them when paused. So the user can press 'p' which pauses the game and windows it, so he can get his email, etc. Unpausing the game returns it to full screen.
You may think from reading some game programming forums that full screen is never appropriate, but in truth it is appropriate when it is appropriate. :) It is only the over use of it in inappropriate situations that has earned it the reputation of being rude to the user.
Greg
11/04/2007 (2:37 pm)
Jerrod, I am right in the middle of developing a game tutorial that is directly on point with what you are talking about, so forgive the rant.If there is any kind of 'ettiquette rule' it is this:
If a game requires complete and total mouse or trackpad control in realtime, like what you are describing, than full screen is appropriate and correct.
If a game does NOT require such complete and total of the mouse in realtime, then full screen is innappropriate and rude.
To illustrate, a Suduko game that forces the user into full screen is annoying; it prevents the user from multitasking, checking email, etc.
A Marble Blast kind of game, where the mouse controls the rolling marble, that plays in a window and NOT full screen is equally annoying. When the mouse leaves the window and you lose control, it takes you out of the realtime experience and is frustrating.
The game you are describing suggests that full screen is the most appropriate option. Hiding the cursor in windowed mode is not recommended. I understand developing in windowed mode, but if your final game is going to have a hidden mouse with realtime mouse control, full screen is the best option for the user and you.
A nice thing to do with full screen games, in my opinon, is to window them when paused. So the user can press 'p' which pauses the game and windows it, so he can get his email, etc. Unpausing the game returns it to full screen.
You may think from reading some game programming forums that full screen is never appropriate, but in truth it is appropriate when it is appropriate. :) It is only the over use of it in inappropriate situations that has earned it the reputation of being rude to the user.
Greg
#7
It's really annoying to have to resize and reposition all your apps just because something forces fullscreen and 800x600.
11/04/2007 (4:49 pm)
I don't mind full-screen applications/games as long as they don't change my resolution (1280x1024) and mess up my desktop icons/apps. For most users this probably doesn't happen but with dual screen monitors, if you change the resolution of the main monitor all the windows and icons on the second monitor move to halfway between each monitor.It's really annoying to have to resize and reposition all your apps just because something forces fullscreen and 800x600.
#8
No problems. In fact, you make a lot of good points, as has everyone else here. I'll have to think more about what I should do in this particular situation, though I desperately need mouse clamping for development at least.
Thanks for all the feedback everyone.
11/05/2007 (1:07 am)
Tetraweb,No problems. In fact, you make a lot of good points, as has everyone else here. I'll have to think more about what I should do in this particular situation, though I desperately need mouse clamping for development at least.
Thanks for all the feedback everyone.
#9
noCursor = "1";
As for making it visible but clamped to the window, I'm not sure.
11/05/2007 (7:58 am)
If you don't want the cursor even visible then you can add this to your mainscreen gui (or whatever you are calling it)noCursor = "1";
As for making it visible but clamped to the window, I'm not sure.
#10
11/05/2007 (9:57 am)
May I suggest you attempt to keep the mouse cursor inside your game window, but that you allow it to exit the window when the CTRL key is pressed (or something similar). The first time the mouse cursor moves to the screen edge, pause the game and pop up a modal dialog box that explains this to the user. I also suggest that when they do move it out of your game's window you automatically pause the game. Provide the user that ability to use SHIFT + CTRL to exit the game window and not pause the game.
Torque Owner DragonSix