Camera in functional state.
This commit is contained in:
@@ -8,18 +8,28 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace RhythmBullet.Zer01HD.Utilities.Camera
|
||||
{
|
||||
class Camera2D
|
||||
public class Camera2D
|
||||
{
|
||||
public float Zoom;
|
||||
public Vector2 Position;
|
||||
public Matrix Transform { get; private set; }
|
||||
|
||||
public void Update(Viewport viewport)
|
||||
public Matrix TransformMatrix { get; private set; }
|
||||
public GraphicsDevice graphicsDevice;
|
||||
|
||||
public Camera2D(GraphicsDevice graphicsDevice)
|
||||
{
|
||||
Transform =
|
||||
Matrix.CreateTranslation(new Vector3(Position.X, Position.Y, 0)) *
|
||||
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(viewport.Width/2f, viewport.Height/2f, 0f));
|
||||
Matrix.CreateTranslation(new Vector3(bounds.Width * 0.5f, bounds.Height * 0.5f, 0f));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,6 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using RhythmBullet.Zer01HD.Utilities.Camera;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -19,15 +20,16 @@ namespace RhythmBullet.Zer01HD.Utilities.ScreenSystem
|
||||
public Screen NextScreen { get; protected set; }
|
||||
public Rectangle ScreenSize { get; protected set; }
|
||||
public bool Initiated { get; private set; }
|
||||
|
||||
public Camera2D Camera { get; private set; }
|
||||
public Screen(bool useEnterTransition = false)
|
||||
{
|
||||
State = useEnterTransition ? ScreenState.EnterTransition : ScreenState.Normal;
|
||||
Transitions = new List<ITransition>();
|
||||
}
|
||||
|
||||
public void Initiate(GraphicsDevice graphicsDevice, Rectangle screenSize)
|
||||
public void Initiate(GraphicsDevice graphicsDevice, Rectangle screenSize, Camera2D camera)
|
||||
{
|
||||
this.Camera = camera;
|
||||
this.ScreenSize = screenSize;
|
||||
GraphicsDevice = graphicsDevice;
|
||||
Initiated = true;
|
||||
|
@@ -1,5 +1,6 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using RhythmBullet.Zer01HD.Utilities.Camera;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
@@ -32,12 +33,12 @@ namespace RhythmBullet.Zer01HD.UI.Modular
|
||||
this.font = font;
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch batch)
|
||||
public override void Draw(SpriteBatch batch, Camera2D camera)
|
||||
{
|
||||
position.X = Bounds.X;
|
||||
position.Y = Bounds.Y;
|
||||
batch.DrawString(font, DisplayedText, position, Color);
|
||||
base.Draw(batch);
|
||||
base.Draw(batch, camera);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using RhythmBullet.Zer01HD.Utilities.Camera;
|
||||
using RhythmBullet.Zer01HD.Utilities.Input;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -21,7 +22,7 @@ namespace RhythmBullet.Zer01HD.UI.Modular
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void Draw(SpriteBatch batch)
|
||||
public virtual void Draw(SpriteBatch batch, Camera2D camera)
|
||||
{
|
||||
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ using System.Threading.Tasks;
|
||||
using Microsoft.Xna.Framework;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
using Microsoft.Xna.Framework.Input;
|
||||
using RhythmBullet.Zer01HD.Utilities.Camera;
|
||||
using RhythmBullet.Zer01HD.Utilities.Input;
|
||||
|
||||
namespace RhythmBullet.Zer01HD.UI.Modular
|
||||
@@ -24,12 +25,12 @@ namespace RhythmBullet.Zer01HD.UI.Modular
|
||||
}
|
||||
}
|
||||
|
||||
public override void Draw(SpriteBatch batch)
|
||||
public override void Draw(SpriteBatch batch, Camera2D camera)
|
||||
{
|
||||
if (scissorBounds != null)
|
||||
{
|
||||
batch.End();
|
||||
batch.Begin(SpriteSortMode.Deferred, null, null, null, scissorRasterizer);
|
||||
batch.Begin(SpriteSortMode.Deferred, null, null, null, scissorRasterizer, null, camera.TransformMatrix);
|
||||
scissorBounds.Width = Bounds.Width;
|
||||
scissorBounds.Height = Bounds.Height;
|
||||
scissorBounds.X = Bounds.X;
|
||||
@@ -44,7 +45,7 @@ namespace RhythmBullet.Zer01HD.UI.Modular
|
||||
int offsetY = module.Bounds.Y;
|
||||
module.Bounds.X = Bounds.X + offsetX;
|
||||
module.Bounds.Y = Bounds.Y + offsetY;
|
||||
module.Draw(batch);
|
||||
module.Draw(batch, camera);
|
||||
module.Bounds.X = offsetX;
|
||||
module.Bounds.Y = offsetY;
|
||||
}
|
||||
@@ -53,7 +54,7 @@ namespace RhythmBullet.Zer01HD.UI.Modular
|
||||
{
|
||||
batch.GraphicsDevice.ScissorRectangle = scissorBounds;
|
||||
batch.End();
|
||||
batch.Begin();
|
||||
batch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, camera.TransformMatrix);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user