Time for action – moving the camera with the mouse
1. In the
TankBattlesGame
class, add five fields to the declarations area:Point screenCenter; Point saveMousePoint; bool moveMode = false; float scrollRate = 1.0f; MouseState previousMouse;
2. In the
Initialize()
method of theTankBattlesGame
class, add the following before the call tobase.Initialize()
:screenCenter.X = this.Window.ClientBounds.Width / 2; screenCenter.Y = this.Window.ClientBounds.Height / 2; this.IsMouseVisible = true; previousMouse = Mouse.GetState(); Mouse.SetPosition(screenCenter.X, screenCenter.Y);
3. In the
Update()
method of theTankBattlesGame
class, add the following before the call tobase.Update()
:if (this.IsActive) { MouseState mouse = Mouse.GetState(); if (moveMode) { camera.Rotation += MathHelper.ToRadians( (mouse.X - screenCenter.X) / 2f); camera.Elevation += MathHelper.ToRadians( (mouse.Y - screenCenter.Y) / 2f); Mouse.SetPosition(screenCenter.X, screenCenter...