Time for action – the Camera class
Create a new class called
Camera.cs
in the "Tile Engine" project.Add the following
using
directive to the top of the class file:using Microsoft.Xna.Framework;
Modify the declaration of the Camera class to make it public and static:
public static class Camera
Add declarations to the Camera class:
#region Declarations private static Vector2 position = Vector2.Zero; private static Vector2 viewPortSize = Vector2.Zero; private static Rectangle worldRectangle = new Rectangle(0, 0, 0, 0); #endregion
Add properties to the Camera class:
#region Properties public static Vector2 Position { get { return position; } set { position = new Vector2( MathHelper.Clamp(value.X, worldRectangle.X, worldRectangle.Width - ViewPortWidth), MathHelper.Clamp(value.Y, worldRectangle.Y, worldRectangle.Height - ViewPortHeight)); } } public static Rectangle WorldRectangle { ...