//----------------------------------------------------------------------------- // LoadingScreen.cs // // Microsoft XNA Community Game Platform // Copyright (C) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- using System; using System.Threading; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Storage; namespace AlienGameSample { /// /// This just loads all content we're going to use on a background thread. It doesn't /// draw anything because it's supposed to be invoked in front of the background screen and right /// before the main menu (i.e. noone will notice). This saves us from spinning up the drive later /// and stalling between menu and gameplay. /// class LoadingScreen : GameScreen { private Thread backgroundThread; /// /// The constructor is private: loading screens should /// be activated via the static Load method instead. /// public LoadingScreen() { TransitionOnTime = TimeSpan.FromSeconds(0.0); TransitionOffTime = TimeSpan.FromSeconds(0.0); } public override void LoadContent() { // Create the thread here (instead of the ctor), so we can guarantee that loading content will work if (backgroundThread == null) { backgroundThread = new Thread(BackgroundLoadContent); backgroundThread.Start(); } base.LoadContent(); } void BackgroundLoadContent() { // First thing we need to do is get a valid storage device for loading and saving // high scores. Since this is a background thread, we can block on it; rendering the guide // for Xbox 360 will happen on the main thread. StorageDevice device = StorageDevice.ShowStorageDeviceGuide(); ScreenManager.Game.Services.AddService(typeof(StorageDevice), device); /*ScreenManager.Game.Content.Load("Alien_Hit"); ScreenManager.Game.Content.Load("alien1"); ScreenManager.Game.Content.Load("background"); ScreenManager.Game.Content.Load("badguy_blue"); ScreenManager.Game.Content.Load("badguy_green"); ScreenManager.Game.Content.Load("badguy_orange"); ScreenManager.Game.Content.Load("badguy_red"); ScreenManager.Game.Content.Load("bullet"); ScreenManager.Game.Content.Load("cloud1"); ScreenManager.Game.Content.Load("cloud2"); ScreenManager.Game.Content.Load("fire"); ScreenManager.Game.Content.Load("gamefont"); ScreenManager.Game.Content.Load("ground"); ScreenManager.Game.Content.Load("hills"); ScreenManager.Game.Content.Load("laser"); ScreenManager.Game.Content.Load("menufont"); ScreenManager.Game.Content.Load("moon"); ScreenManager.Game.Content.Load("mountains_blurred"); ScreenManager.Game.Content.Load("Player_Hit"); ScreenManager.Game.Content.Load("scorefont"); ScreenManager.Game.Content.Load("smoke"); ScreenManager.Game.Content.Load("sun"); ScreenManager.Game.Content.Load("tank"); ScreenManager.Game.Content.Load("tank_fire"); ScreenManager.Game.Content.Load("tank_tire"); ScreenManager.Game.Content.Load("tank_top"); ScreenManager.Game.Content.Load("title"); ScreenManager.Game.Content.Load("titlefont");*/ } /// /// Updates the loading screen. /// public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen) { // See if the loading has completed... if (backgroundThread != null && backgroundThread.Join(10)) { backgroundThread = null; this.ExitScreen(); ScreenManager.AddScreen(new MainMenuScreen()); ScreenManager.Game.ResetElapsedTime(); } base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen); } } }