Game1.cs 3.5 KB

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