Game1.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. using Microsoft.Xna.Framework.Input;
  4. namespace Tutorial027
  5. {
  6. /// <summary>
  7. /// This is the main type for your game.
  8. /// </summary>
  9. public class Game1 : Game
  10. {
  11. GraphicsDeviceManager graphics;
  12. SpriteBatch spriteBatch;
  13. public Game1()
  14. {
  15. graphics = new GraphicsDeviceManager(this);
  16. Content.RootDirectory = "Content";
  17. }
  18. /// <summary>
  19. /// Allows the game to perform any initialization it needs to before starting to run.
  20. /// This is where it can query for any required services and load any non-graphic
  21. /// related content. Calling base.Initialize will enumerate through any components
  22. /// and initialize them as well.
  23. /// </summary>
  24. protected override void Initialize()
  25. {
  26. // TODO: Add your initialization logic here
  27. base.Initialize();
  28. }
  29. /// <summary>
  30. /// LoadContent will be called once per game and is the place to load
  31. /// all of your content.
  32. /// </summary>
  33. protected override void LoadContent()
  34. {
  35. // Create a new SpriteBatch, which can be used to draw textures.
  36. spriteBatch = new SpriteBatch(GraphicsDevice);
  37. // TODO: use this.Content to load your game content here
  38. }
  39. /// <summary>
  40. /// UnloadContent will be called once per game and is the place to unload
  41. /// game-specific content.
  42. /// </summary>
  43. protected override void UnloadContent()
  44. {
  45. // TODO: Unload any non ContentManager content here
  46. }
  47. /// <summary>
  48. /// Allows the game to run logic such as updating the world,
  49. /// checking for collisions, gathering input, and playing audio.
  50. /// </summary>
  51. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  52. protected override void Update(GameTime gameTime)
  53. {
  54. if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
  55. Exit();
  56. // TODO: Add your update logic here
  57. base.Update(gameTime);
  58. }
  59. /// <summary>
  60. /// This is called when the game should draw itself.
  61. /// </summary>
  62. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  63. protected override void Draw(GameTime gameTime)
  64. {
  65. GraphicsDevice.Clear(Color.CornflowerBlue);
  66. // TODO: Add your drawing code here
  67. base.Draw(gameTime);
  68. }
  69. }
  70. }