GameScene.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #region Using Statements
  2. using System.Collections.Generic;
  3. using Microsoft.Xna.Framework;
  4. #endregion
  5. namespace RockRainIphone.Core
  6. {
  7. /// <summary>
  8. /// This is the base class for all game scenes.
  9. /// </summary>
  10. public abstract class GameScene : DrawableGameComponent
  11. {
  12. /// <summary>
  13. /// List of child GameComponents
  14. /// </summary>
  15. private readonly List<GameComponent> components;
  16. public GameScene(Game game)
  17. : base(game)
  18. {
  19. components = new List<GameComponent>();
  20. Visible = false;
  21. Enabled = false;
  22. }
  23. /// <summary>
  24. /// Show the scene
  25. /// </summary>
  26. public virtual void Show()
  27. {
  28. Visible = true;
  29. Enabled = true;
  30. }
  31. /// <summary>
  32. /// Hide the scene
  33. /// </summary>
  34. public virtual void Hide()
  35. {
  36. Visible = false;
  37. Enabled = false;
  38. }
  39. /// <summary>
  40. /// Components of Game Scene
  41. /// </summary>
  42. public List<GameComponent> Components
  43. {
  44. get { return components; }
  45. }
  46. /// <summary>
  47. /// Allows the game component to update itself.
  48. /// </summary>
  49. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  50. public override void Update(GameTime gameTime)
  51. {
  52. // Update the child GameComponents
  53. for (int i = 0; i < components.Count; i++)
  54. {
  55. if (components[i].Enabled)
  56. {
  57. components[i].Update(gameTime);
  58. }
  59. }
  60. base.Update(gameTime);
  61. }
  62. /// <summary>
  63. /// Allows the game component draw your content in game screen
  64. /// </summary>
  65. public override void Draw(GameTime gameTime)
  66. {
  67. // Draw the child GameComponents (if drawable)
  68. for (int i = 0; i < components.Count; i++)
  69. {
  70. GameComponent gc = components[i];
  71. if ((gc is DrawableGameComponent) &&
  72. ((DrawableGameComponent) gc).Visible)
  73. {
  74. ((DrawableGameComponent) gc).Draw(gameTime);
  75. }
  76. }
  77. base.Draw(gameTime);
  78. }
  79. }
  80. }