Keeping the pointer in the screen center
by Timlon · in Torque Game Builder · 04/10/2005 (3:40 pm) · 13 replies
Hi Chaps,
The main method of control for the player in my game is the mouse, because of this I am obviously reading the mouse position and using the amount it has moved since the last time to move the player. For this to work properly I need to keep positioning the cursor to the centre of the game screen (like you would in an fps) - anyone know how to do this?
Thanks :)
The main method of control for the player in my game is the mouse, because of this I am obviously reading the mouse position and using the amount it has moved since the last time to move the player. For this to work properly I need to keep positioning the cursor to the centre of the game screen (like you would in an fps) - anyone know how to do this?
Thanks :)
About the author
#2
04/11/2005 (1:27 am)
I answered this on IRC... but you should be able to use Canvas.setCursorPos(x,y);
#3
If you dont clamp the mouse to the centre of the screen when it reaches the edges you wont receive any movement data.
Lab - you did :) thank you, I posted this before jumping onto the irc.
04/11/2005 (4:00 am)
Brian - play the famous TGE Orc demo or any fps game and you will see what i mean - it's a very normal thing to do.If you dont clamp the mouse to the centre of the screen when it reaches the edges you wont receive any movement data.
Lab - you did :) thank you, I posted this before jumping onto the irc.
#4
The command Harold gave is a TGE Script command. IE You can already do this in T2D totally with script.
You need to slow down getting on your soapbox all the time man. You're constantly over reacting. Maybe drink less coffee.
04/11/2005 (6:27 am)
Who said anything about C++?The command Harold gave is a TGE Script command. IE You can already do this in T2D totally with script.
You need to slow down getting on your soapbox all the time man. You're constantly over reacting. Maybe drink less coffee.
#5
04/11/2005 (6:50 am)
Wouldn't it be more easy to display a static sprite in the middle of the screen, disable the mouse cursor and use the mouse event infos to update your camera?
#6
Sorry, for those who dont know, the Canvas.setCursorPos(x,y); function is broken and requires a fix in the engine source - big thanks to Harold (Labrat) for telling us of the command and pointing out it doesnt work (and showing me the source to fix it).
Robert's concern is that he is not a c++ chap and so won't be able to use Canvas.setCursorPos(x,y); unless it is fixed by the big fellas.
04/11/2005 (7:44 am)
Quote:Who said anything about C++?
Sorry, for those who dont know, the Canvas.setCursorPos(x,y); function is broken and requires a fix in the engine source - big thanks to Harold (Labrat) for telling us of the command and pointing out it doesnt work (and showing me the source to fix it).
Robert's concern is that he is not a c++ chap and so won't be able to use Canvas.setCursorPos(x,y); unless it is fixed by the big fellas.
#7
In any case if its a bug then i'm sure it will be fixed. Thats a base TGE command though.
04/11/2005 (8:06 am)
Odd never knew it was broken. Pretty sure i'd used it before.In any case if its a bug then i'm sure it will be fixed. Thats a base TGE command though.
#8
04/11/2005 (8:50 am)
The fix should be getting added to base TGE and thus T2D.... I'm kinda surprised it isnt'... I'll see if Ben can get it added to 1.4 if it isn't.
#9
If you don't want to see the T2D cursor and still want it locked as above then just call..
Also note that the fxSceneWindow2D has a "lockMouse" option in the GUI editor under "General" for those who want this to be the default.
Look in "common\client\cursor.cs" for more info on the above commands.
Typically for games that use the mouse like this, the cursor disappears. Pressing something like ESCAPE then shows a menu turns the cursor back on.
This is known as capturing the mouse and is the standard way of handling it.
Nothing to get all hot under the collar about. ;)
- Melv.
04/11/2005 (12:07 pm)
Just call...lockMouse(true);... that way your bindings will continue to give you updates. Internally, T2D sets the SYSTEM cursor to the center of the window and locks the mouse to the T2D window. Note that the T2D cursor still functions because it simple calculates where you are relatively moving it. I haven't tried this in a while but it should work fine.
If you don't want to see the T2D cursor and still want it locked as above then just call..
cursorOff();... which locks the mouse and disables it.
Also note that the fxSceneWindow2D has a "lockMouse" option in the GUI editor under "General" for those who want this to be the default.
Look in "common\client\cursor.cs" for more info on the above commands.
Typically for games that use the mouse like this, the cursor disappears. Pressing something like ESCAPE then shows a menu turns the cursor back on.
This is known as capturing the mouse and is the standard way of handling it.
Nothing to get all hot under the collar about. ;)
- Melv.
#10
Thanks for your response. I did try LockMouse ( true ); but the problem is, that function restricts the mouse to the confines of the game window ( which is dead handy for other purposes of course! ). The mouse callbacks work fine with LockMouse but work on the world position of the mouse - so once the mouse reaches the edge of the screen - no more movement in that direction is allowed.
Is there a way to return the amount the mouse has been moved (even if it has infact appeared to have stayed still due to the LockMouse() function )? - this is what I am really after.
The player in my game moves around by use of the mouse - although much slower than the mouse pointer and with inertia etc and will never reach the end of the screen like the actual cursor does.
Thanks :)
04/11/2005 (12:40 pm)
Hi Melv,Thanks for your response. I did try LockMouse ( true ); but the problem is, that function restricts the mouse to the confines of the game window ( which is dead handy for other purposes of course! ). The mouse callbacks work fine with LockMouse but work on the world position of the mouse - so once the mouse reaches the edge of the screen - no more movement in that direction is allowed.
Is there a way to return the amount the mouse has been moved (even if it has infact appeared to have stayed still due to the LockMouse() function )? - this is what I am really after.
The player in my game moves around by use of the mouse - although much slower than the mouse pointer and with inertia etc and will never reach the end of the screen like the actual cursor does.
Thanks :)
#11
04/12/2005 (4:58 pm)
Thanks mate - lovely.
#12
09/12/2005 (7:05 pm)
Did anyone get this problem solved? I need pretty much what Timlon described, ie, the mouse needs to be reset when it hits the edge of the screen so it doesn't stop at the edges and we get continuous deltas.
#13
09/13/2005 (2:12 pm)
I solved this by resetting the mouse position (Canvas.setCursorPosition()) in onUpdateScene(). Shouldn't this be supported by Torque since all FPS games need this kind of feature? Anybody know if it's buried in there somewhere so I don't have use a script hack?
Torque Owner Brian Wilson
Yes, all of us know that we can regain a mouse by bringing another application to focus, but not all of your players will be that educated.