proper splash screen loading as well as proper unloading assets for end of game finished.
This commit is contained in:
parent
831c49b685
commit
b77aa6d7fd
Binary file not shown.
Before Width: | Height: | Size: 346 KiB After Width: | Height: | Size: 597 KiB |
@ -23,19 +23,18 @@ namespace RhythmBullet
|
|||||||
public const int WORLD_HEIGHT = 3;
|
public const int WORLD_HEIGHT = 3;
|
||||||
public static int pixels_per_WU;
|
public static int pixels_per_WU;
|
||||||
|
|
||||||
public GraphicsDeviceManager Graphics;
|
GraphicsDeviceManager graphics;
|
||||||
SpriteBatch spriteBatch;
|
SpriteBatch spriteBatch;
|
||||||
|
public Color BackgroundColor;
|
||||||
public readonly ContentSystem Assets;
|
public readonly ContentSystem Assets;
|
||||||
readonly ResolutionContentResolver resolutionContentResolver;
|
readonly ResolutionContentResolver resolutionContentResolver;
|
||||||
public PreferencesManager preferencesManager;
|
public PreferencesManager preferencesManager;
|
||||||
private Screen currentScreen;
|
private Screen currentScreen;
|
||||||
|
private bool resizing;
|
||||||
public RhythmBulletGame()
|
public RhythmBulletGame()
|
||||||
{
|
{
|
||||||
Graphics = new GraphicsDeviceManager(this);
|
graphics = new GraphicsDeviceManager(this);
|
||||||
Graphics.PreferredBackBufferWidth = 320;
|
BackgroundColor = new Color(0, 0, 0, 255);
|
||||||
Graphics.PreferredBackBufferHeight = 320;
|
|
||||||
Window.IsBorderless = true;
|
|
||||||
Content.RootDirectory = "Content";
|
Content.RootDirectory = "Content";
|
||||||
Assets = new ContentSystem(Content);
|
Assets = new ContentSystem(Content);
|
||||||
resolutionContentResolver = new ResolutionContentResolver();
|
resolutionContentResolver = new ResolutionContentResolver();
|
||||||
@ -45,6 +44,10 @@ namespace RhythmBullet
|
|||||||
preferencesManager = new PreferencesManager(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/RhythmBullet",
|
preferencesManager = new PreferencesManager(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "/RhythmBullet",
|
||||||
new General(),
|
new General(),
|
||||||
new Controls());
|
new Controls());
|
||||||
|
preferencesManager.Load();
|
||||||
|
Resolution resolution = preferencesManager.GetPreferences<General>().Resolution;
|
||||||
|
graphics.PreferredBackBufferWidth = resolution.Width;
|
||||||
|
graphics.PreferredBackBufferHeight = resolution.Height;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Screen Screen
|
public Screen Screen
|
||||||
@ -72,13 +75,9 @@ namespace RhythmBullet
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
protected override void Initialize()
|
protected override void Initialize()
|
||||||
{
|
{
|
||||||
//Load preferences
|
|
||||||
preferencesManager.Load();
|
|
||||||
|
|
||||||
Resolution resolution = preferencesManager.GetPreferences<General>().Resolution;
|
Resolution resolution = preferencesManager.GetPreferences<General>().Resolution;
|
||||||
resolutionContentResolver.Width = resolution.Width;
|
resolutionContentResolver.Width = resolution.Width;
|
||||||
resolutionContentResolver.Height = resolution.Height;
|
resolutionContentResolver.Height = resolution.Height;
|
||||||
QueueContent();
|
|
||||||
Debug.WriteLine("Initial setup complete.");
|
Debug.WriteLine("Initial setup complete.");
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
}
|
}
|
||||||
@ -91,8 +90,8 @@ 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);
|
||||||
Screen = new LoadingScreen(Content.Load<Texture2D>("RhythmBullet"), new Rectangle(0,0, Graphics.PreferredBackBufferWidth, Graphics.PreferredBackBufferHeight));
|
QueueContent();
|
||||||
// TODO: use this.Content to load your game content here
|
Screen = new SplashScreen(this, new Rectangle(0, 0, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -101,7 +100,7 @@ namespace RhythmBullet
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
protected override void UnloadContent()
|
protected override void UnloadContent()
|
||||||
{
|
{
|
||||||
// TODO: Unload any non ContentManager content here
|
Assets.UnloadAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -114,6 +113,10 @@ namespace RhythmBullet
|
|||||||
if (!Assets.Done)
|
if (!Assets.Done)
|
||||||
{
|
{
|
||||||
Assets.Update();
|
Assets.Update();
|
||||||
|
} else if (resizing)
|
||||||
|
{
|
||||||
|
resizing = false;
|
||||||
|
PostResize();
|
||||||
}
|
}
|
||||||
Screen.Update(gameTime);
|
Screen.Update(gameTime);
|
||||||
|
|
||||||
@ -126,7 +129,7 @@ namespace RhythmBullet
|
|||||||
/// <param name="gameTime">Provides a snapshot of timing values.</param>
|
/// <param name="gameTime">Provides a snapshot of timing values.</param>
|
||||||
protected override void Draw(GameTime gameTime)
|
protected override void Draw(GameTime gameTime)
|
||||||
{
|
{
|
||||||
GraphicsDevice.Clear(Color.Transparent);
|
GraphicsDevice.Clear(BackgroundColor);
|
||||||
spriteBatch.Begin();
|
spriteBatch.Begin();
|
||||||
Screen.Draw(spriteBatch);
|
Screen.Draw(spriteBatch);
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
@ -134,21 +137,26 @@ namespace RhythmBullet
|
|||||||
base.Draw(gameTime);
|
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();
|
Assets.UnloadAll();
|
||||||
resolutionContentResolver.Width = Graphics.PreferredBackBufferWidth;
|
|
||||||
resolutionContentResolver.Height = Graphics.PreferredBackBufferHeight;
|
|
||||||
QueueContent();
|
QueueContent();
|
||||||
Screen.AssetLoadStateChange(true);
|
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);
|
Screen.AssetLoadStateChange(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void QueueContent()
|
private void QueueContent()
|
||||||
{
|
{
|
||||||
Assets.Queue<Texture2D>("Tech-Circle1");
|
Assets.Queue<Texture2D>("Tech-Circle1");
|
||||||
Assets.Queue<Texture2D>("polyjet-standard");
|
Assets.Queue<Texture2D>("polyjet-standard");
|
||||||
|
@ -34,7 +34,8 @@ namespace RhythmBullet.Zer01HD.Utilities.ContentSystem
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
assets.Add(assetName, contentManager.Load<IDisposable>(path));
|
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("Failed to load " + assetName + "with modified path: " + cle.Message);
|
||||||
Debug.WriteLine("Loading asset from root: " + assetName);
|
Debug.WriteLine("Loading asset from root: " + assetName);
|
||||||
@ -98,6 +99,8 @@ namespace RhythmBullet.Zer01HD.Utilities.ContentSystem
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="name">the string name used to load the asset</param>
|
/// <param name="name">the string name used to load the asset</param>
|
||||||
public void Remove(string name)
|
public void Remove(string name)
|
||||||
|
{
|
||||||
|
lock (queue)
|
||||||
{
|
{
|
||||||
if (assets.ContainsKey(name))
|
if (assets.ContainsKey(name))
|
||||||
{
|
{
|
||||||
@ -105,6 +108,7 @@ namespace RhythmBullet.Zer01HD.Utilities.ContentSystem
|
|||||||
assets.Remove(name);
|
assets.Remove(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Clears the queue.
|
/// Clears the queue.
|
||||||
@ -122,13 +126,13 @@ namespace RhythmBullet.Zer01HD.Utilities.ContentSystem
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void UnloadAll()
|
public void UnloadAll()
|
||||||
{
|
{
|
||||||
foreach (KeyValuePair<string, IDisposable> asset in assets)
|
lock (queue)
|
||||||
{
|
{
|
||||||
asset.Value.Dispose();
|
contentManager.Unload();
|
||||||
assets.Remove(asset.Key);
|
assets.Clear();
|
||||||
}
|
|
||||||
ClearQueue();
|
ClearQueue();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public bool Done
|
public bool Done
|
||||||
{
|
{
|
||||||
|
@ -5,20 +5,46 @@ using RhythmBullet.Zer01HD.UI;
|
|||||||
using RhythmBullet.Zer01HD.Utilities.UI;
|
using RhythmBullet.Zer01HD.Utilities.UI;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace RhythmBullet.Zer01HD.Game
|
namespace RhythmBullet.Zer01HD.Game
|
||||||
{
|
{
|
||||||
class LoadingScreen : Screen
|
class SplashScreen : Screen
|
||||||
{
|
{
|
||||||
Texture2D recrown;
|
Texture2D recrown;
|
||||||
Rectangle rectangleBounds;
|
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.recrown = rhythmBullet.Content.Load<Texture2D>("RhythmBullet");
|
||||||
this.rectangleBounds = bounds;
|
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)
|
public override void Draw(SpriteBatch spriteBatch)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user