Camera in functional state.
This commit is contained in:
parent
3c44a52a8f
commit
a2defc5d11
@ -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);
|
||||
@ -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<Texture2D>("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);
|
||||
}
|
||||
|
||||
|
@ -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 Matrix TransformMatrix { get; private set; }
|
||||
public GraphicsDevice graphicsDevice;
|
||||
|
||||
public void Update(Viewport viewport)
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user