rhythmbullet/RhythmBullet/Zer01HD/Utilities/Camera/Camera2D.cs

36 lines
1.1 KiB
C#

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RhythmBullet.Zer01HD.Utilities.Camera
{
public class Camera2D
{
public float Zoom;
public Vector2 Position;
public Matrix TransformMatrix { get; private set; }
public GraphicsDevice graphicsDevice;
public Camera2D(GraphicsDevice graphicsDevice)
{
this.graphicsDevice = graphicsDevice;
Zoom = 1f;
Position.X = this.graphicsDevice.Viewport.Width * 0.5f;
Position.Y = this.graphicsDevice.Viewport.Height * 0.5f;
}
public void Update()
{
Rectangle bounds = graphicsDevice.Viewport.Bounds;
TransformMatrix =
Matrix.CreateTranslation(new Vector3(-Position.X, -Position.Y, 0)) *
Matrix.CreateScale(Zoom) *
Matrix.CreateTranslation(new Vector3(bounds.Width * 0.5f, bounds.Height * 0.5f, 0f));
}
}
}