TestTexture.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using Microsoft.Xna.Framework;
  3. using Microsoft.Xna.Framework.Content;
  4. using Microsoft.Xna.Framework.Graphics;
  5. namespace BackgroundThreadTester
  6. {
  7. public class TestTexture : DrawableGameComponent
  8. {
  9. Texture2D texture;
  10. int x, y;
  11. static Random random = new Random();
  12. Game1 game;
  13. SpriteBatch spriteBatch;
  14. Vector2 position;
  15. public TestTexture (Game1 game) : base (game)
  16. {
  17. this.game = game;
  18. }
  19. public override void Initialize ()
  20. {
  21. base.Initialize ();
  22. }
  23. protected override void LoadContent ()
  24. {
  25. texture = game.Content.Load<Texture2D>("beehive");
  26. // Create a random position
  27. x = random.Next(0, this.game.GetBackBufferWidth () - texture.Width);
  28. y = random.Next(0, this.game.GetBackBufferHeight () - texture.Height);
  29. position = new Vector2(x,y);
  30. // Create a new spritebatch
  31. spriteBatch = new SpriteBatch(this.Game.GraphicsDevice);
  32. }
  33. public override void Draw (GameTime gameTime)
  34. {
  35. spriteBatch.Begin();
  36. spriteBatch.Draw(texture, position, Color.White);
  37. spriteBatch.End();
  38. }
  39. }
  40. }