BackgroundScreen.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // BackgroundScreen.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. #region Using Statements
  10. using System;
  11. using Microsoft.Xna.Framework;
  12. using Microsoft.Xna.Framework.Graphics;
  13. #endregion
  14. namespace HoneycombRush
  15. {
  16. class BackgroundScreen : GameScreen
  17. {
  18. #region Fields
  19. Texture2D background;
  20. string backgroundName;
  21. #endregion
  22. #region Initialization
  23. /// <summary>
  24. /// Creates a new background screen.
  25. /// </summary>
  26. /// <param name="backgroundName">Name of the background texture to use.</param>
  27. public BackgroundScreen(string backgroundName)
  28. {
  29. TransitionOnTime = TimeSpan.FromSeconds(0.0);
  30. TransitionOffTime = TimeSpan.FromSeconds(0.5);
  31. this.backgroundName = backgroundName;
  32. }
  33. /// <summary>
  34. /// Load screen resources.
  35. /// </summary>
  36. public override void LoadContent()
  37. {
  38. background = ScreenManager.Game.Content.Load<Texture2D>("Textures/Backgrounds/" + backgroundName);
  39. base.LoadContent();
  40. }
  41. #endregion
  42. #region Update
  43. /// <summary>
  44. /// Update the screen.
  45. /// </summary>
  46. /// <param name="gameTime">Game time information.</param>
  47. /// <param name="otherScreenHasFocus">Whether or not another screen currently has the focus.</param>
  48. /// <param name="coveredByOtherScreen">Whether or not this screen is covered by another.</param>
  49. public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
  50. {
  51. base.Update(gameTime, otherScreenHasFocus, false);
  52. }
  53. #endregion
  54. #region Render
  55. /// <summary>
  56. /// Renders the screen.
  57. /// </summary>
  58. /// <param name="gameTime">Game time information.</param>
  59. public override void Draw(GameTime gameTime)
  60. {
  61. SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
  62. spriteBatch.Begin();
  63. // Draw background
  64. spriteBatch.Draw(background, ScreenManager.GraphicsDevice.Viewport.Bounds, Color.White * TransitionAlpha);
  65. spriteBatch.End();
  66. }
  67. #endregion
  68. }
  69. }