Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have tried making a custom mouse cursor, hiding the real mouse, taking the real mouse delta and clamping it to a maximum speed. Here is the problem:

  • In windowed mode, the "real" mouse cursor moves off the window while the custom mouse cursor (since it's movement is being scaled) is still somewhere inside the game window. This becomes bizarre and is obviously not desired, as clicking at this point means clicking on things outside the game window. Is there any way to accomplish this in windowed mode?

  • In fullscreen mode, the "real" mouse cursor is bounded to the edges of the screen. So I get to a point where there is no more mouse delta, yet my custom cursor is still somewhere in the middle of the screen and hence can't move further in that direction. If I wanted to clamp it to the edge of the screen when the real cursor is at the edge, then I would get an abrupt jump to the edge of the screen, which isn't desired either

Any help would be appreciated. I'd like to be able to limit the speed of the mouse.

share|improve this question
10  
Personally, I get really annoyed when games start to play with my mouse. –  John McDonald Nov 14 '11 at 18:52
    
I can understand that and only turned to the "limit speed" question initially because of the juddering. However, I'm thinking I may want to have multiplayer in the future (where people are "racing" against each other to complete some task), and it would be nice to dissuade them from getting an edge by changing their mouse speed. –  idlewire Nov 14 '11 at 19:06
3  
Then you should probably fix the rules of the game so that having a fast mouse pointer doesn't give a specific advantage. For instance, by implementing a rest time (like Kung-fu chess does) or limiting the number of actions per second. Personally I hate when a game changes my mouse speed, too, and I view such games as lagging. –  Sam Hocevar Nov 14 '11 at 19:58
    
Nah, I'm not going to redesign the flow of the game just for this. Maybe I'll just feel flattered if someone goes through the trouble to change their mouse speed just to get an advantage. –  idlewire Nov 15 '11 at 4:14
add comment

2 Answers

up vote 3 down vote accepted

Let's get the obvious stuff out of the way, the tool is there: http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.input.mouse.setposition.aspx

In fullscreen it is easy to use, just do some controlled repositionings and the edge problem is gone. For some other games this could lead to the problem of a trapped mouse in windowed mode, but if you do it just right I think you may solve your problem without upsetting John McDonald:

Whenever the player has moved the mouse too quickly, reposition it to where the game cursor ends up, this way the player can actually still drag the mouse outside the window if so desired, and you don't get the clamping problem until you'd have to cap the cursor movement anyway.

share|improve this answer
    
Yeah, you're right. I personally don't think clamping max speed should be a problem. It'll just feel like old DOS games (that totally slowed down when you moved the mouse to fast, so it feels like you're moving thru tar). If there's motion of say, 5px or more (in x, y independently) then clamp the motion to 5px, and use SetPosition to enforce it –  bobobobo Nov 14 '11 at 21:29
    
I actually didn't know there was a SetPosition method, so thanks for that. This helped me with my second question, and I realized I should only have asked one question (I may ask the first in a later question). So I've edited it to only reflect the part that you helped answer and marking yours as the answer. –  idlewire Dec 2 '11 at 4:35
add comment

Your object should follow the cursor...

Vector2 MousePos = Mouse.GetState().Position;

if (dragging)
{
   YourObject.Position += 0.1f * (MousePos - YourObject.Position);
}
share|improve this answer
    
That's not what I want at all, which should be clear from the start of my question, where I am striving for 1:1 movement, not "following"-type behavior. –  idlewire Nov 15 '11 at 4:10
    
When you stop moving the cursor, the position is 1:1, you should test different ratios, and choose the more confortable to you... I continue thinking is the best of the bad options... ;) –  Blau Nov 15 '11 at 13:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.