2
\$\begingroup\$

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.

\$\endgroup\$
4
  • 10
    \$\begingroup\$ Personally, I get really annoyed when games start to play with my mouse. \$\endgroup\$ Commented Nov 14, 2011 at 18:52
  • \$\begingroup\$ 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. \$\endgroup\$
    – idlewire
    Commented Nov 14, 2011 at 19:06
  • 3
    \$\begingroup\$ 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. \$\endgroup\$ Commented Nov 14, 2011 at 19:58
  • \$\begingroup\$ 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. \$\endgroup\$
    – idlewire
    Commented Nov 15, 2011 at 4:14

2 Answers 2

3
\$\begingroup\$

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.

\$\endgroup\$
2
  • \$\begingroup\$ 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 \$\endgroup\$
    – bobobobo
    Commented Nov 14, 2011 at 21:29
  • \$\begingroup\$ 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. \$\endgroup\$
    – idlewire
    Commented Dec 2, 2011 at 4:35
2
\$\begingroup\$

Your object should follow the cursor...

Vector2 MousePos = Mouse.GetState().Position;

if (dragging)
{
   YourObject.Position += 0.1f * (MousePos - YourObject.Position);
}
\$\endgroup\$
2
  • \$\begingroup\$ 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. \$\endgroup\$
    – idlewire
    Commented Nov 15, 2011 at 4:10
  • \$\begingroup\$ 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... ;) \$\endgroup\$
    – Blau
    Commented Nov 15, 2011 at 13:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .