Glen654
Glen654

Reputation: 1152

How to set the cursor's position in c# XNA

So I am pretty new to XNA, but I've figured out how to create a camera object and control it. I want to have some more intuitive controls for my camera, because when the cursor hit's the edge of the screen with the following code, the rotation stops. And that's a little unintuitive.

I want to be able to reset the cursor's position to the middle of the screen, how can I do this?

MouseState mouseState = Mouse.GetState();

yaw -= (mouseState.X - oldx) / 600.0f;
pitch -= (mouseState.Y - oldy) / 600.0f;

oldx = mouseState.X;
oldy = mouseState.Y;

Upvotes: 2

Views: 3577

Answers (1)

Asik
Asik

Reputation: 22123

To set the mouse position to the middle of the screen:

Mouse.SetPosition(GraphicsDevice.Viewport.Width / 2, GraphicsDevice.Viewport.Height / 2);

You can see an example of this at Riemers XNA Tutorials.

Upvotes: 5

Related Questions