proper splash screen loading as well as proper unloading assets for end of game finished.

This commit is contained in:
Harrison Deng 2018-10-31 01:10:15 -05:00
parent 831c49b685
commit b77aa6d7fd
4 changed files with 69 additions and 31 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 346 KiB

After

Width:  |  Height:  |  Size: 597 KiB

View File

@ -23,19 +23,18 @@ namespace RhythmBullet
public const int WORLD_HEIGHT = 3;
public static int pixels_per_WU;
public GraphicsDeviceManager Graphics;
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
public Color BackgroundColor;
public readonly ContentSystem Assets;
readonly ResolutionContentResolver resolutionContentResolver;
public PreferencesManager preferencesManager;
private Screen currentScreen;
private bool resizing;
public RhythmBulletGame()
{
Graphics = new GraphicsDeviceManager(this);
Graphics.PreferredBackBufferWidth = 320;
Graphics.PreferredBackBufferHeight = 320;
Window.IsBorderless = true;
graphics = new GraphicsDeviceManager(this);
BackgroundColor = new Color(0, 0, 0, 255);
Content.RootDirectory = "Content";
Assets = new ContentSystem(Content);
resolutionContentResolver = new ResolutionContentResolver();
@ -45,6 +44,10 @@ namespace RhythmBullet
preferencesManager = new PreferencesManager(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/RhythmBullet",
new General(),
new Controls());
preferencesManager.Load();
Resolution resolution = preferencesManager.GetPreferences<General>().Resolution;
graphics.PreferredBackBufferWidth = resolution.Width;
graphics.PreferredBackBufferHeight = resolution.Height;
}
public Screen Screen
@ -72,13 +75,9 @@ namespace RhythmBullet
/// </summary>
protected override void Initialize()
{
//Load preferences
preferencesManager.Load();
Resolution resolution = preferencesManager.GetPreferences<General>().Resolution;
resolutionContentResolver.Width = resolution.Width;
resolutionContentResolver.Height = resolution.Height;
QueueContent();
Debug.WriteLine("Initial setup complete.");
base.Initialize();
}
@ -91,8 +90,8 @@ namespace RhythmBullet
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
Screen = new LoadingScreen(Content.Load<Texture2D>("RhythmBullet"), new Rectangle(0,0, Graphics.PreferredBackBufferWidth, Graphics.PreferredBackBufferHeight));
// TODO: use this.Content to load your game content here
QueueContent();
Screen = new SplashScreen(this, new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight));
}
/// <summary>
@ -101,7 +100,7 @@ namespace RhythmBullet
/// </summary>
protected override void UnloadContent()
{
// TODO: Unload any non ContentManager content here
Assets.UnloadAll();
}
/// <summary>
@ -114,6 +113,10 @@ namespace RhythmBullet
if (!Assets.Done)
{
Assets.Update();
} else if (resizing)
{
resizing = false;
PostResize();
}
Screen.Update(gameTime);
@ -126,7 +129,7 @@ namespace RhythmBullet
/// <param name="gameTime">Provides a snapshot of timing values.</param>
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Transparent);
GraphicsDevice.Clear(BackgroundColor);
spriteBatch.Begin();
Screen.Draw(spriteBatch);
spriteBatch.End();
@ -134,21 +137,26 @@ namespace RhythmBullet
base.Draw(gameTime);
}
public void PreAssetLoad()
public void Resize(int width, int height)
{
resolutionContentResolver.Width = width;
resolutionContentResolver.Height = height;
graphics.PreferredBackBufferWidth = width;
graphics.PreferredBackBufferHeight = height;
resizing = true;
Assets.UnloadAll();
resolutionContentResolver.Width = Graphics.PreferredBackBufferWidth;
resolutionContentResolver.Height = Graphics.PreferredBackBufferHeight;
QueueContent();
Screen.AssetLoadStateChange(true);
Screen = new SplashScreen(this, new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight));
}
public void PostAssetLoad()
private void PostResize()
{
graphics.ApplyChanges();
Screen.AssetLoadStateChange(false);
}
void QueueContent()
private void QueueContent()
{
Assets.Queue<Texture2D>("Tech-Circle1");
Assets.Queue<Texture2D>("polyjet-standard");

View File

@ -34,7 +34,8 @@ namespace RhythmBullet.Zer01HD.Utilities.ContentSystem
try
{
assets.Add(assetName, contentManager.Load<IDisposable>(path));
} catch (ContentLoadException cle)
}
catch (ContentLoadException cle)
{
Debug.WriteLine("Failed to load " + assetName + "with modified path: " + cle.Message);
Debug.WriteLine("Loading asset from root: " + assetName);
@ -99,10 +100,13 @@ namespace RhythmBullet.Zer01HD.Utilities.ContentSystem
/// <param name="name">the string name used to load the asset</param>
public void Remove(string name)
{
if (assets.ContainsKey(name))
lock (queue)
{
assets[name].Dispose();
assets.Remove(name);
if (assets.ContainsKey(name))
{
assets[name].Dispose();
assets.Remove(name);
}
}
}
@ -122,12 +126,12 @@ namespace RhythmBullet.Zer01HD.Utilities.ContentSystem
/// </summary>
public void UnloadAll()
{
foreach (KeyValuePair<string, IDisposable> asset in assets)
lock (queue)
{
asset.Value.Dispose();
assets.Remove(asset.Key);
contentManager.Unload();
assets.Clear();
ClearQueue();
}
ClearQueue();
}
public bool Done

View File

@ -5,20 +5,46 @@ using RhythmBullet.Zer01HD.UI;
using RhythmBullet.Zer01HD.Utilities.UI;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace RhythmBullet.Zer01HD.Game
{
class LoadingScreen : Screen
class SplashScreen : Screen
{
Texture2D recrown;
Rectangle rectangleBounds;
public LoadingScreen(Texture2D recrown, Rectangle bounds)
float proportion = 0.4f;
RhythmBulletGame rhythmBullet;
float progress;
public SplashScreen(RhythmBulletGame rhythmBullet, Rectangle dimensions)
{
this.recrown = recrown;
this.rectangleBounds = bounds;
this.recrown = rhythmBullet.Content.Load<Texture2D>("RhythmBullet");
this.rhythmBullet = rhythmBullet;
rectangleBounds = new Rectangle(0, 0, (int)(dimensions.Height * proportion), (int)(dimensions.Height * proportion));
rectangleBounds.X = (dimensions.Width - rectangleBounds.Width) / 2;
rectangleBounds.Y = (dimensions.Height - rectangleBounds.Height) / 2;
}
public override void Update(GameTime gameTime)
{
if (progress < 0.8f)
{
float delta = (float) gameTime.ElapsedGameTime.TotalSeconds;
progress += (delta/6f);
if (progress > 1f)
{
progress = 1f;
}
rhythmBullet.BackgroundColor.R = (byte)(progress * 255);
rhythmBullet.BackgroundColor.G = (byte)(progress * 255);
rhythmBullet.BackgroundColor.B = (byte)(progress * 255);
}
base.Update(gameTime);
}
public override void Draw(SpriteBatch spriteBatch)