Showing posts with label screen manager. Show all posts
Showing posts with label screen manager. Show all posts

Wednesday, November 2, 2016

43. How to Add Splash Screens to the Menu System


       The following tutorial is based on the Game State Management Sample and shows how to add splash screens as the startup of the game. This tutorial also works with the Network Game State Management Sample. I have posted my entire class below with comments that you can add to your screens folder. I named mine SplaceScreens.cs and make sure to change the namespace of this class to match your project. Also check out Robot Foot Games' tutorial on how to add multiple columns to the Game State Management Sample.


#region File Description
/*  ============================================
 *  SplashScreens.cs
 *  ============================================
 *
 * Upon the game's startup, Splash Screens are shown. The first screen shows the 
 * company logo and then it slowly fades away and displays the game engine logo. 
 * After the game engine logo fades away, the user is taken to the Title Screen.
 * 
 * 
*/
#endregion


#region Using Statements
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
#endregion

namespace CycloneGameEngine
{
    class SplashScreens : GameScreen
  {
      #region Fields
      public enum GameType { Splash1, Splash2}
   
      GameType gametype = new GameType();
   
      #region Splash Screens

      #region Studio Logo
      Texture2D StudioLogo;
      float logoFade = 0;
      bool wasNorm = false;
      bool logoStarted = false;
      #endregion End of Studio Logo

      #region Engine Logo
      Texture2D EngineLogo;
      float logoFade2 = 0;
      bool wasNorm2 = false;
      bool logoStarted2 = false;
      #endregion End of Engine Logo

      #endregion End of Splash Screens

        ContentManager content;
   
        #endregion


        #region Initialization

        // Constructor.
        public SplashScreens()
        {
     
        }


        // Loads graphics content for this screen. The background texture is quite
        // big, so we use our own local ContentManager to load it. This allows us
        // to unload before going from the menus into the game itself, wheras if we
        // used the shared ContentManager provided by the Game class, the content
        // would remain loaded forever.
        //
        public override void LoadContent()
        {
            if (content == null)
                content = new ContentManager(ScreenManager.Game.Services, "Content");

            StudioLogo = content.Load<Texture2D>("Images/Splash_Screens/logo2Main");
            EngineLogo = content.Load<Texture2D>("Images/Splash_Screens/Engine-Logo");
        }



        // Unloads graphics content for this screen.
        public override void UnloadContent()
        {
            content.Unload();
        }

        #endregion


        #region Update and Draw


        // Updates the background screen. Unlike most screens, this should not
        // transition off even if it has been covered by another screen: it is
        // supposed to be covered, after all! This overload forces the
        // coveredByOtherScreen parameter to false in order to stop the base
        // Update method wanting to transition off.
        public override void Update(GameTime gameTime, bool otherScreenHasFocus,
                                                       bool coveredByOtherScreen)
        {
            #region Update the 1st Splash Screen
            gametype = GameType.Splash1;

            // If we are at the splash screen
            if (gametype == GameType.Splash1)
            {

                if (!logoStarted)
                {
                    logoStarted = true;
                }

                // Fade the logo in , then out.
                if ((logoFade <= 245) && (wasNorm == false))
                    logoFade += (float)0.8;
                if (logoFade > 244)
                    wasNorm = true;
                if ((logoFade > 11) && (wasNorm == true))
                    logoFade -= 1;
                if ((logoFade < 11) && (wasNorm == true))
                {
                    gametype = GameType.Splash2;
                }
            }
            #endregion End of Drawing the 1st Splash Screen


            #region Update 2nd Splash Screen
            if (gametype == GameType.Splash2)
            {

                if (!logoStarted2)
                {
                    logoStarted2 = true;
                }

                // Fade the logo in , then out.
                if ((logoFade2 <= 245) && (wasNorm2 == false))
                    logoFade2 += (float)0.8;
                if (logoFade2 > 244)
                    wasNorm2 = true;
                if ((logoFade2 > 11) && (wasNorm2 == true))
                    logoFade2 -= 1;
                if ((logoFade2 < 11) && (wasNorm2 == true))
                {
                    ExitScreen();
                 
                }
            }
            #endregion End of Drawing the 2nd Splash Screen

            base.Update(gameTime, false, false);

        }


        // Draws the splash screens.
        public override void Draw(GameTime gameTime)
        {
            SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
         
            #region Draw the 1st Splash Screen
            if (gametype == GameType.Splash1)
            {
                // Set the background color to black
                ScreenManager.GraphicsDevice.Clear(Color.Black);
                spriteBatch.Begin(SpriteSortMode.Texture, BlendState.Additive, SamplerState.PointWrap, DepthStencilState.Default, null);

                // Draw the logo to screen.              
                spriteBatch.Draw(StudioLogo, new Vector2(ScreenManager.GraphicsDevice.Viewport.Width / 2 - (StudioLogo.Width / 2), ScreenManager.GraphicsDevice.Viewport.Height / 2 - (StudioLogo.Height / 2)), new Color(255, 255, 255, (byte)logoFade));

                // End the spritebatch
                spriteBatch.End();
            }
            #endregion End of Drawing the 1st Splash Screen

            #region Draw the 2nd Splash Screen
            if (gametype == GameType.Splash2)
            {
                // Set the background color to black
                ScreenManager.GraphicsDevice.Clear(Color.Black);
                spriteBatch.Begin(SpriteSortMode.Texture, BlendState.Additive, SamplerState.PointWrap, DepthStencilState.Default, null);

                // Draw the logo to screen.              
                spriteBatch.Draw(EngineLogo, new Vector2(ScreenManager.GraphicsDevice.Viewport.Width / 2 - (EngineLogo.Width / 2), ScreenManager.GraphicsDevice.Viewport.Height / 2 - (EngineLogo.Height / 2)), new Color(255, 255, 255, (byte)logoFade2));

                // End the spritebatch
                spriteBatch.End();

            }
            #endregion End of Drawing the 2nd Splash Screen
        }
        #endregion
  }
}



Friday, June 3, 2016

39. Engine Update 5 Teaser


       This is a brief video teaser sneak peek of my next game engine update. Everything is still a work-in-progress. Since rigged and non-rigged models can be attached to the character now, I am working on character customization. Soon, players will be able to customize their armor. They will be able to swap out head-wear such as hats, helmets and mask. Soon they will also be able to swap between chest pieces and knee guards. This might not be fully shown in the next video update but I have this working for the most part. As players progress through the game, the upgrades to their suit will greatly improve their gameplay experience. Lately, I have been building up content for creating the models and assets that will go into the game world. I am improving artificial intelligence at the moment. This is just a teaser, so it will be a while before my next engine video update. I have been focusing on my 2D game and my independent studies to further educate myself and make far more progress. I am taking some time off and working on the gameplay! So excited. Below are some more screenshots of some fun I had with armor customization.







Sunday, November 3, 2013

12: Cyclone Game Engine Update 3



       Sorry for not posting videos for a while. This is not the latest progress video but an older one. This is a short video showing that I successfully created a working 2D/ 3D menu system with the help of the game state management's screen manager. I also got the menu system capable of displaying splash screens with transition effects upon the start-up of the game. The menu system also supports 3D models within it and description text when you hover over different menu items. I also got a sky-box functioning in the game. This video also shows the lens flare effect functioning and placed over the sun on the sky-box.  Its tricky when the program is drawing 2d and 3d together on the same screen under the 'Draw Method'.

       Thanks to Shawn Hargreaves who provided the most efficient way to go in his blog post, I was able to fix my skybox. When I was mixing 3D rendering with 2D objects using SpriteBatch, I may noticed that my 3D graphics no longer draw correctly after you have rendered sprites. All of the models triangles and polygons appeared to be disoriented and stretched leaving tons of gaps and holes. This is because the SpriteBatch changes several device renderstates. At this stage the actual game is still in Pre-Production Phase of development and I won't be revealing too much until the game is near completion. For now, I am improving the game engine and plan to post more progress footage of it. To see more progress, visit the Steel Cyclone Studio's Facebook Page. Below are some work-in-progress screenshots of 3D models I am creating.


Garage Interior WIP




Gun Model WIPs

       These are screenshots of a assault rifles I modeled which for now are just placeholders, not for an actual game. The M4A1 and M-16 are high-poly models which might have other attachments as later. The gun as well as the hands are arms in most of these screenshots were not rigged yet. I am still learning animation so the only in-game animations at the moment are programmed for when the gun shoots and turns slightly to indicate sprint. The arms in the screenshots below are simply a place-holder. Next I will be working on attaching the gun models to the animated character marine model shown in the video above. These gun model will most likely be used in starter kits I plan on putting together in the future. These models are all work-in-progress so they are not "perfect" by any means. 


M4A1


 ACR






Scar








M-16

The iron sight for instance is a bit too big, but the holographic sight is almost proportional. 







The iron sight needs to be a bit smaller. When you aim-down-sights, it would obscure the player's view at the moment, getting in the way.