Restricting Mouse to Screen Bounds
Introduction
Keeping the mouse a the center of the screen
if(FlatRedBallServices.Game.IsActive)
{
var centerX = FlatRedBallServices.Game.Window.ClientBounds.Width/2;
var centerY = FlatRedBallServices.Game.Window.ClientBounds.Height/2;
Microsoft.Xna.Framework.Input.Mouse.SetPosition(centerOfWindowX, centerOfWindowY);
}Keeping the mouse bound to the window
[DllImport("user32.dll")]
static extern void ClipCursor(ref Rectangle rect);
protected override void Update(GameTime gameTime)
{
if (IsActive)
{
Rectangle rect = Window.ClientBounds;
rect.Width += rect.X;
rect.Height += rect.Y;
ClipCursor(ref rect);
}
base.Update(gameTime);
}Last updated
Was this helpful?