BackgroundScreen.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //-----------------------------------------------------------------------------
  2. // BackgroundScreen.cs
  3. //
  4. // Microsoft XNA Community Game Platform
  5. // Copyright (C) Microsoft Corporation. All rights reserved.
  6. //-----------------------------------------------------------------------------
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using Microsoft.Xna.Framework.Graphics;
  12. using Microsoft.Xna.Framework;
  13. namespace CatapultGame
  14. {
  15. class BackgroundScreen : GameScreen
  16. {
  17. Texture2D background;
  18. public BackgroundScreen()
  19. {
  20. TransitionOnTime = TimeSpan.FromSeconds(0.0);
  21. TransitionOffTime = TimeSpan.FromSeconds(0.5);
  22. }
  23. public override void LoadContent()
  24. {
  25. background = Load<Texture2D>("Textures/Backgrounds/title_screen");
  26. }
  27. /// <summary>
  28. /// Updates the background screen. Unlike most screens, this should not
  29. /// transition off even if it has been covered by another screen: it is
  30. /// supposed to be covered, after all! This overload forces the
  31. /// coveredByOtherScreen parameter to false in order to stop the base
  32. /// Update method wanting to transition off.
  33. /// </summary>
  34. public override void Update(GameTime gameTime, bool otherScreenHasFocus,
  35. bool coveredByOtherScreen)
  36. {
  37. base.Update(gameTime, otherScreenHasFocus, false);
  38. }
  39. public override void Draw(GameTime gameTime)
  40. {
  41. SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
  42. spriteBatch.Begin(SpriteSortMode.Deferred, null, null, null, null, null, ScreenManager.GlobalTransformation);
  43. // Draw Background
  44. spriteBatch.Draw(background, new Vector2(0, 0),
  45. new Color(255, 255, 255, TransitionAlpha));
  46. spriteBatch.End();
  47. }
  48. }
  49. }