Game1.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System;
  2. using Microsoft.Xna;
  3. using Microsoft.Xna.Framework;
  4. using Microsoft.Xna.Framework.Graphics;
  5. using Microsoft.Xna.Framework.Media;
  6. using Microsoft.Xna.Framework.Input;
  7. namespace Microsoft.Xna.Samples.VideoSample
  8. {
  9. /// <summary>
  10. /// This is the main type for your game
  11. /// </summary>
  12. public class Game1 : Microsoft.Xna.Framework.Game
  13. {
  14. GraphicsDeviceManager graphics;
  15. SpriteBatch spriteBatch;
  16. SpriteFont font;
  17. Video video;
  18. VideoPlayer player;
  19. public Game1 ()
  20. {
  21. graphics = new GraphicsDeviceManager (this);
  22. Content.RootDirectory = "Content";
  23. graphics.IsFullScreen = true;
  24. }
  25. /// <summary>
  26. /// Allows the game to perform any initialization it needs to before starting to run.
  27. /// This is where it can query for any required services and load any non-graphic
  28. /// related content. Calling base.Initialize will enumerate through any components
  29. /// and initialize them as well.
  30. /// </summary>
  31. protected override void Initialize ()
  32. {
  33. // TODO: Add your initialization logic here
  34. player = new VideoPlayer(this);
  35. base.Initialize ();
  36. }
  37. /// <summary>
  38. /// LoadContent will be called once per game and is the place to load
  39. /// all of your content.
  40. /// </summary>
  41. protected override void LoadContent ()
  42. {
  43. // Create a new SpriteBatch, which can be used to draw textures.
  44. spriteBatch = new SpriteBatch (GraphicsDevice);
  45. //TODO: use this.Content to load your game content here
  46. font = Content.Load<SpriteFont>("SpriteFont1");
  47. video = Content.Load<Video>("MonoGame.m4v");
  48. }
  49. /// <summary>
  50. /// Allows the game to run logic such as updating the world,
  51. /// checking for collisions, gathering input, and playing audio.
  52. /// </summary>
  53. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  54. protected override void Update (GameTime gameTime)
  55. {
  56. // TODO: Add your update logic here
  57. if (Mouse.GetState().X != 0)
  58. {
  59. if (player.State != MediaState.Playing)
  60. player.Play(video);
  61. Mouse.SetPosition(0,0);
  62. }
  63. base.Update (gameTime);
  64. }
  65. /// <summary>
  66. /// This is called when the game should draw itself.
  67. /// </summary>
  68. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  69. protected override void Draw (GameTime gameTime)
  70. {
  71. graphics.GraphicsDevice.Clear (Color.CornflowerBlue);
  72. //TODO: Add your drawing code here
  73. spriteBatch.Begin();
  74. spriteBatch.DrawString(font,"Tap To Play",new Vector2(65,200),Color.Black);
  75. spriteBatch.End();
  76. base.Draw (gameTime);
  77. }
  78. }
  79. }