XNA Mouse Movement

后端 未结 3 548
孤街浪徒
孤街浪徒 2021-01-17 01:56

I\'ve made a few games in XNA before and I\'m about to start a new project. One thing I\'d like to do is have the mouse movement.

Just to clarify (as I\'ve seen some

3条回答
  •  春和景丽
    2021-01-17 02:23

    The MouseState class includes only the position of the mouse cursor, among other things. This position will, as you mentioned, clip to the edges of the screen. There is no way to determine whether the user moved the mouse other than through the MouseState class. In particular, there is no MouseDirection, MouseTangent, or MouseAngle property that indicates which direction the mouse was moved.

    As a workaround, you can call SetPosition to force the cursor at the middle of the screen, so you can always know which direction the mouse has moved. In fact, SetPosition even recommends this approach:

    When using this method to take relative input, such as in a first-person game, set the position of the mouse to the center of your game window each frame. This will allow you to read mouse movement on both axes with the greatest amount of granularity.

提交回复
热议问题