Game Development Community

Keeping the Cursor inside the window

by Garrett Brown · in Torque Game Builder · 03/31/2006 (3:38 pm) · 3 replies

Hey all,
My problem is that whenever I move the cursor to the edge of my t2d window, it leaves the game and the user can click on windows stuff in the background. I want the cursor to stay inside the t2d window, but can't seem to find a way to do this. Does anybody have any suggestions? Right now I'm using t2dSceneWindow::SetMousePosition(x,y). Any help would be appreciated.

-Garrett

About the author

I work at n-Space, located in Orlando, FL as a designer. When I'm not there, I work on side projects, generally using TGB. Side projects I've finished are Oddictive, Klockotock, and AstroDriller3020


#1
03/31/2006 (3:55 pm)
I think you will need to hack the engine sources to do that. Also your players probably won't appreciate this since they will have to quit the game to check their email, IMs or whatever. Most commercial games will just allow them to click away, and the game will pause when that occurs. Try to play nice with your players :)
#2
03/31/2006 (3:58 pm)
Huh, never really thought of that. I was thinkin that people might accidentally click off the screen and get mad that the game lost focus. But yeah, you're right, most games don't do this. Thanks then, less work to for me.
#3
03/31/2006 (6:30 pm)
There's a built-in command called lockMouse(boolean) that will keep the cursor in the game window. This harkens back to TGE, as it is used for first-person viewpoint control.

The usability of this depends on the kind of game you're making. Breakout-style games certainly benefit from not accidentally moving the mouse so far out of the window that you end up accidentally activating some other application. In that case you should have either a mouse-press or keyboard command that pauses the game and 'unlocks' the mouse so users can do what they wish. Also you should respect an Alt-Tab and unlock the cursor in that case too.