diff --git a/RhythmBullet/RhythmBulletGame.cs b/RhythmBullet/RhythmBulletGame.cs index 963e444..6610c17 100644 --- a/RhythmBullet/RhythmBulletGame.cs +++ b/RhythmBullet/RhythmBulletGame.cs @@ -5,6 +5,7 @@ using RhythmBullet.Zer01HD.Game.ContentResolvers; using RhythmBullet.Zer01HD.Game.Preferences; using RhythmBullet.Zer01HD.Game.Screens; using RhythmBullet.Zer01HD.Utilities; +using RhythmBullet.Zer01HD.Utilities.Camera; using RhythmBullet.Zer01HD.Utilities.ContentSystem; using RhythmBullet.Zer01HD.Utilities.DataTypes; using RhythmBullet.Zer01HD.Utilities.Input; @@ -32,6 +33,7 @@ namespace RhythmBullet private RenderTarget2D previousScreenRenderTarget; private Screen currentScreen; private bool resizing; + private Camera2D camera; public Screen Screen { get @@ -44,7 +46,7 @@ namespace RhythmBullet currentScreen = value; if (!Screen.Initiated) { - Screen.Initiate(graphics.GraphicsDevice, new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight)); + Screen.Initiate(graphics.GraphicsDevice, new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight), camera); } if (previousScreen != null && previousScreenRenderTarget == null && previousScreen.UseRenderTargetForExitTransition) { @@ -64,6 +66,7 @@ namespace RhythmBullet graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; Assets = new ContentSystem(Content); + resolutionContentResolver = new ResolutionContentResolver(); FontContentResolver fcr = new FontContentResolver(resolutionContentResolver); Assets.contentPathModifier.Add(typeof(Texture2D), resolutionContentResolver); @@ -80,7 +83,7 @@ namespace RhythmBullet /// /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic - /// related content. Calling base.Initialize will enumerate through any components + /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// protected override void Initialize() @@ -100,6 +103,7 @@ namespace RhythmBullet { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); + camera = new Camera2D(graphics.GraphicsDevice); QueueContent(); Screen = new LoadingScreen(Content.Load("RhythmBullet"), 0.7f); } @@ -160,6 +164,7 @@ namespace RhythmBullet } InputUtilities.Update(); + camera.Update(); base.Update(gameTime); } @@ -174,16 +179,15 @@ namespace RhythmBullet { graphics.GraphicsDevice.SetRenderTarget(previousScreenRenderTarget); GraphicsDevice.Clear(previousScreen.BackgroundColor); - spriteBatch.Begin(); + spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, camera.TransformMatrix); previousScreen.Draw(spriteBatch); spriteBatch.End(); graphics.GraphicsDevice.SetRenderTarget(null); Screen.UpdatePreviousScreenFrame(previousScreenRenderTarget); } - spriteBatch.Begin(); + spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, camera.TransformMatrix); Screen.Draw(spriteBatch); spriteBatch.End(); - base.Draw(gameTime); } diff --git a/RhythmBullet/Zer01HD/Utilities/Camera/Camera2D.cs b/RhythmBullet/Zer01HD/Utilities/Camera/Camera2D.cs index 592ff9a..75e1da4 100644 --- a/RhythmBullet/Zer01HD/Utilities/Camera/Camera2D.cs +++ b/RhythmBullet/Zer01HD/Utilities/Camera/Camera2D.cs @@ -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)); } } } diff --git a/RhythmBullet/Zer01HD/Utilities/ScreenSystem/Screen.cs b/RhythmBullet/Zer01HD/Utilities/ScreenSystem/Screen.cs index 6730c48..721df28 100644 --- a/RhythmBullet/Zer01HD/Utilities/ScreenSystem/Screen.cs +++ b/RhythmBullet/Zer01HD/Utilities/ScreenSystem/Screen.cs @@ -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(); } - 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; diff --git a/RhythmBullet/Zer01HD/Utilities/UI/Modular/Text.cs b/RhythmBullet/Zer01HD/Utilities/UI/Modular/Text.cs index 8ee435a..dae846a 100644 --- a/RhythmBullet/Zer01HD/Utilities/UI/Modular/Text.cs +++ b/RhythmBullet/Zer01HD/Utilities/UI/Modular/Text.cs @@ -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); } } } diff --git a/RhythmBullet/Zer01HD/Utilities/UI/Modular/UIModule.cs b/RhythmBullet/Zer01HD/Utilities/UI/Modular/UIModule.cs index 5a0a01a..aaa4ae7 100644 --- a/RhythmBullet/Zer01HD/Utilities/UI/Modular/UIModule.cs +++ b/RhythmBullet/Zer01HD/Utilities/UI/Modular/UIModule.cs @@ -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) { } diff --git a/RhythmBullet/Zer01HD/Utilities/UI/Modular/UIModuleGroup.cs b/RhythmBullet/Zer01HD/Utilities/UI/Modular/UIModuleGroup.cs index b1f8768..c606dc3 100644 --- a/RhythmBullet/Zer01HD/Utilities/UI/Modular/UIModuleGroup.cs +++ b/RhythmBullet/Zer01HD/Utilities/UI/Modular/UIModuleGroup.cs @@ -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); } }