UEXDev

SceneBase Implementierung

May 6th, 2012
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | None | 0 0
  1. public abstract class SceneBase : DrawableGameComponent
  2. {
  3.     public List<GameComponent> SceneComponents { get; private set; }
  4.  
  5.     public SceneBase(Game game)
  6.         : base(game)
  7.     {
  8.         SceneComponents = new List<GameComponent>();
  9.  
  10.         Visible = false;
  11.         Enabled = false;
  12.     }
  13.  
  14.     public void Show()
  15.     {
  16.         Enabled = true;
  17.         Visible = true;
  18.     }
  19.  
  20.     public void Hide()
  21.     {
  22.         Enabled = false;
  23.         Visible = false;
  24.     }
  25.  
  26.     public void Pause()
  27.     {
  28.         Enabled = false;
  29.         Visible = true;
  30.     }
  31.    
  32.     public override void Update(GameTime gameTime)
  33.     {
  34.         foreach (var component in SceneComponents
  35.             .Where(x => x.Enabled))
  36.         {
  37.             component.Update(gameTime);
  38.         }
  39.  
  40.         base.Update(gameTime);
  41.     }
  42.  
  43.     public override void Draw(GameTime gameTime)
  44.     {
  45.         foreach (var component in SceneComponents
  46.             .OfType<DrawableGameComponent>()
  47.             .Where(x => x.Visible))
  48.         {
  49.             component.Draw(gameTime);
  50.         }
  51.  
  52.         base.Draw(gameTime);
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment