Advertisement
maxkhl

SceneManager.cs

Jan 7th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.99 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Microsoft.Xna.Framework;
  6. using Microsoft.Xna.Framework.Graphics;
  7. using Microsoft.Xna.Framework.Input;
  8.  
  9. namespace Horn_War_II
  10. {
  11.     /// <summary>
  12.     /// Used to manage scenes
  13.     /// </summary>
  14.     class SceneManager
  15.     {
  16.         /// <summary>
  17.         /// Currently running scene. Set method is not thread safe!
  18.         /// </summary>
  19.         public Scene ActiveScene
  20.         {
  21.             get
  22.             {
  23.                 return _ActiveScene;
  24.             }
  25.             set
  26.             {
  27.                 //Dispose old scene
  28.                 if(_ActiveScene != null)
  29.                     _ActiveScene.Dispose();
  30.  
  31.                 _ActiveScene = value;
  32.  
  33.                 //Load new scene
  34.                 if (_ActiveScene != null)
  35.                     _ActiveScene.LoadContent();
  36.             }
  37.         }
  38.         private Scene _ActiveScene;
  39.  
  40.         /// <summary>
  41.         /// Attached game
  42.         /// </summary>
  43.         public static HornWarII Game { get; set; }
  44.  
  45.         /// <summary>
  46.         /// Constructor
  47.         /// </summary>
  48.         /// <param name="Game">Attached game</param>
  49.         public SceneManager(HornWarII HWGame)
  50.         {
  51.             Game = HWGame;
  52.         }
  53.  
  54.         /// <summary>
  55.         /// The currently active scene will be updated in here.
  56.         /// </summary>
  57.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  58.         public void Update(GameTime gameTime)
  59.         {
  60.             if (ActiveScene != null)
  61.                 ActiveScene.Update(gameTime);
  62.         }
  63.  
  64.         /// <summary>
  65.         /// The currently active scene will be drawn in here.
  66.         /// </summary>
  67.         /// <param name="gameTime">Provides a snapshot of timing values.</param>
  68.         public void Draw(GameTime gameTime)
  69.         {            
  70.             if (ActiveScene != null)
  71.                 ActiveScene.Draw(gameTime);
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement