basic transition system for between screen transitions (restructured folders)
This commit is contained in:
parent
0e4a4564cf
commit
9c50226eb7
@ -51,7 +51,7 @@
|
|||||||
<Compile Include="Zer01HD\Utilities\Persistence\Preferences.cs" />
|
<Compile Include="Zer01HD\Utilities\Persistence\Preferences.cs" />
|
||||||
<Compile Include="Zer01HD\Utilities\Renderer\ScaledRenderer.cs" />
|
<Compile Include="Zer01HD\Utilities\Renderer\ScaledRenderer.cs" />
|
||||||
<Compile Include="Zer01HD\Utilities\UI\LoadingScreen.cs" />
|
<Compile Include="Zer01HD\Utilities\UI\LoadingScreen.cs" />
|
||||||
<Compile Include="Zer01HD\Game\MainScreen\MainScreen.cs" />
|
<Compile Include="Zer01HD\Game\Screens\MainScreen.cs" />
|
||||||
<Compile Include="Zer01HD\Utilities\UI\Modular\Module.cs" />
|
<Compile Include="Zer01HD\Utilities\UI\Modular\Module.cs" />
|
||||||
<Compile Include="Zer01HD\Utilities\UI\Modular\ModuleGroup.cs" />
|
<Compile Include="Zer01HD\Utilities\UI\Modular\ModuleGroup.cs" />
|
||||||
<Compile Include="RhythmBulletGame.cs" />
|
<Compile Include="RhythmBulletGame.cs" />
|
||||||
|
@ -34,7 +34,7 @@ namespace RhythmBullet
|
|||||||
public RhythmBulletGame()
|
public RhythmBulletGame()
|
||||||
{
|
{
|
||||||
graphics = new GraphicsDeviceManager(this);
|
graphics = new GraphicsDeviceManager(this);
|
||||||
|
BackgroundColor = Color.Black;
|
||||||
Content.RootDirectory = "Content";
|
Content.RootDirectory = "Content";
|
||||||
Assets = new ContentSystem(Content);
|
Assets = new ContentSystem(Content);
|
||||||
resolutionContentResolver = new ResolutionContentResolver();
|
resolutionContentResolver = new ResolutionContentResolver();
|
||||||
@ -91,7 +91,7 @@ namespace RhythmBullet
|
|||||||
// Create a new SpriteBatch, which can be used to draw textures.
|
// Create a new SpriteBatch, which can be used to draw textures.
|
||||||
spriteBatch = new SpriteBatch(GraphicsDevice);
|
spriteBatch = new SpriteBatch(GraphicsDevice);
|
||||||
QueueContent();
|
QueueContent();
|
||||||
Screen = new LoadingScreen(this, new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight));
|
Screen = new LoadingScreen(Content.Load<Texture2D>("RhythmBullet"), new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -118,7 +118,21 @@ namespace RhythmBullet
|
|||||||
resizing = false;
|
resizing = false;
|
||||||
PostResize();
|
PostResize();
|
||||||
}
|
}
|
||||||
Screen.Update(gameTime);
|
switch (Screen.State) {
|
||||||
|
case ScreenState.EnterTransition:
|
||||||
|
Screen.EnteringTransition(gameTime.ElapsedGameTime.TotalSeconds, Assets.Done, ref BackgroundColor);
|
||||||
|
break;
|
||||||
|
case ScreenState.ExitTransition:
|
||||||
|
Screen transitionScreen = Screen.ExitingTransition(gameTime.ElapsedGameTime.TotalSeconds, Assets.Done, ref BackgroundColor);
|
||||||
|
if (transitionScreen != null)
|
||||||
|
{
|
||||||
|
Screen = transitionScreen;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ScreenState.Normal:
|
||||||
|
Screen.Update(gameTime);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
base.Update(gameTime);
|
base.Update(gameTime);
|
||||||
}
|
}
|
||||||
@ -148,7 +162,7 @@ namespace RhythmBullet
|
|||||||
Assets.UnloadAll();
|
Assets.UnloadAll();
|
||||||
QueueContent();
|
QueueContent();
|
||||||
Screen.AssetLoadStateChange(true);
|
Screen.AssetLoadStateChange(true);
|
||||||
Screen = new LoadingScreen(this, new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight));
|
Screen = new LoadingScreen(Content.Load<Texture2D>("RhythmBullet"), new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PostResize()
|
private void PostResize()
|
||||||
|
@ -7,12 +7,10 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace RhythmBullet.Zer01HD.Game.MainScreen
|
namespace RhythmBullet.Zer01HD.Game.Screens
|
||||||
{
|
{
|
||||||
class MainScreen : Screen
|
class MainScreen : Screen
|
||||||
{
|
{
|
||||||
Viewport viewport = new Viewport();
|
|
||||||
|
|
||||||
public MainScreen()
|
public MainScreen()
|
||||||
{
|
{
|
||||||
|
|
@ -1,60 +1,86 @@
|
|||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Content;
|
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using RhythmBullet.Zer01HD.UI;
|
using RhythmBullet.Zer01HD.Game.Screens;
|
||||||
using RhythmBullet.Zer01HD.Utilities.UI;
|
using RhythmBullet.Zer01HD.Utilities.UI;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace RhythmBullet.Zer01HD.Game
|
namespace RhythmBullet.Zer01HD.Game
|
||||||
{
|
{
|
||||||
class LoadingScreen : Screen
|
class LoadingScreen : Screen
|
||||||
{
|
{
|
||||||
Texture2D recrown;
|
Texture2D texture;
|
||||||
Color color;
|
Color color;
|
||||||
Rectangle rectangleBounds;
|
Rectangle rectangleBounds;
|
||||||
float proportion = 0.4f;
|
float proportion = 0.5f;
|
||||||
RhythmBulletGame rhythmBullet;
|
bool recorded;
|
||||||
double progress;
|
float rR, rG, rB;
|
||||||
double timePassed;
|
float progR, progG, progB;
|
||||||
public LoadingScreen(RhythmBulletGame rhythmBullet, Rectangle dimensions)
|
float progC = 254;
|
||||||
|
public LoadingScreen(Texture2D texture, Rectangle dimensions) : base(true)
|
||||||
{
|
{
|
||||||
color = Color.White;
|
color = Color.White;
|
||||||
this.recrown = rhythmBullet.Content.Load<Texture2D>("RhythmBullet");
|
this.texture = texture;
|
||||||
this.rhythmBullet = rhythmBullet;
|
|
||||||
rectangleBounds = new Rectangle(0, 0, (int)(dimensions.Height * proportion), (int)(dimensions.Height * proportion));
|
rectangleBounds = new Rectangle(0, 0, (int)(dimensions.Height * proportion), (int)(dimensions.Height * proportion));
|
||||||
rectangleBounds.X = (dimensions.Width - rectangleBounds.Width) / 2;
|
rectangleBounds.X = (dimensions.Width - rectangleBounds.Width) / 2;
|
||||||
rectangleBounds.Y = (dimensions.Height - rectangleBounds.Height) / 2;
|
rectangleBounds.Y = (dimensions.Height - rectangleBounds.Height) / 2;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Update(GameTime gameTime)
|
public override void Update(GameTime gameTime)
|
||||||
{
|
{
|
||||||
if (progress < 1f)
|
|
||||||
{
|
|
||||||
double delta = gameTime.ElapsedGameTime.TotalSeconds;
|
|
||||||
timePassed += delta;
|
|
||||||
progress = timePassed / 4;
|
|
||||||
if (progress > 0.9f)
|
|
||||||
{
|
|
||||||
progress = 0.9f;
|
|
||||||
}
|
|
||||||
rhythmBullet.BackgroundColor.R = (byte)(progress * 255);
|
|
||||||
rhythmBullet.BackgroundColor.G = (byte)(progress * 255);
|
|
||||||
rhythmBullet.BackgroundColor.B = (byte)(progress * 255);
|
|
||||||
|
|
||||||
}
|
|
||||||
base.Update(gameTime);
|
base.Update(gameTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void EnteringTransition(double delta, bool assetsLoaded, ref Color BGColor)
|
||||||
|
{
|
||||||
|
float deltaf = (float)delta;
|
||||||
|
if (progR < 254 || progG < 254 || progB < 254)
|
||||||
|
{
|
||||||
|
if (!recorded)
|
||||||
|
{
|
||||||
|
rR = (Color.White.R - BGColor.R) / 2.5f;
|
||||||
|
rG = (Color.White.G - BGColor.G) / 2.5f;
|
||||||
|
rB = (Color.White.B - BGColor.B) / 2.5f;
|
||||||
|
recorded = true;
|
||||||
|
}
|
||||||
|
progR += rR * deltaf;
|
||||||
|
progR = Math.Min(progR, 254);
|
||||||
|
progG += rG * deltaf;
|
||||||
|
progG = Math.Min(progG, 254);
|
||||||
|
progB += rB * deltaf;
|
||||||
|
progB = Math.Min(progB, 254);
|
||||||
|
BGColor.R = (byte)progR;
|
||||||
|
BGColor.G = (byte)progG;
|
||||||
|
BGColor.B = (byte)progB;
|
||||||
|
}
|
||||||
|
else if (progC > 0)
|
||||||
|
{
|
||||||
|
float rate = deltaf * 255 / 1.5f;
|
||||||
|
progC -= rate;
|
||||||
|
progC = Math.Max(progC, 0);
|
||||||
|
color.R = (byte)progC;
|
||||||
|
color.G = (byte)progC;
|
||||||
|
color.B = (byte)progC;
|
||||||
|
color.A = (byte)progC;
|
||||||
|
}
|
||||||
|
else if (assetsLoaded)
|
||||||
|
{
|
||||||
|
DoneTransition();
|
||||||
|
StartExitTransition();
|
||||||
|
}
|
||||||
|
base.EnteringTransition(delta, assetsLoaded, ref BGColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override Screen ExitingTransition(double delta, bool assetsLoaded, ref Color backgroundColor)
|
||||||
|
{
|
||||||
|
return new MainScreen();
|
||||||
|
}
|
||||||
|
|
||||||
public override void Draw(SpriteBatch spriteBatch)
|
public override void Draw(SpriteBatch spriteBatch)
|
||||||
{
|
{
|
||||||
spriteBatch.Draw(recrown, rectangleBounds, color);
|
spriteBatch.Draw(texture, rectangleBounds, color);
|
||||||
base.Draw(spriteBatch);
|
base.Draw(spriteBatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,8 +8,17 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace RhythmBullet.Zer01HD.Utilities.UI
|
namespace RhythmBullet.Zer01HD.Utilities.UI
|
||||||
{
|
{
|
||||||
|
public enum ScreenState { EnterTransition, ExitTransition, Normal }
|
||||||
|
|
||||||
public class Screen
|
public class Screen
|
||||||
{
|
{
|
||||||
|
ScreenState state;
|
||||||
|
|
||||||
|
public Screen(bool useEnterTransition = false)
|
||||||
|
{
|
||||||
|
state = useEnterTransition ? ScreenState.EnterTransition : ScreenState.Normal;
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void Update(GameTime gameTime)
|
public virtual void Update(GameTime gameTime)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -20,6 +29,16 @@ namespace RhythmBullet.Zer01HD.Utilities.UI
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public virtual void EnteringTransition(double delta, bool assetsLoaded, ref Color backgroundColor)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual Screen ExitingTransition(double delta, bool assetsLoaded, ref Color backgroundColor)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void Show()
|
public virtual void Show()
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -34,5 +53,23 @@ namespace RhythmBullet.Zer01HD.Utilities.UI
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ScreenState State
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DoneTransition()
|
||||||
|
{
|
||||||
|
state = ScreenState.Normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StartExitTransition()
|
||||||
|
{
|
||||||
|
state = ScreenState.ExitTransition;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user