2
0

Object.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using System.Collections.Generic;
  3. using Microsoft.Xna.Framework;
  4. using Microsoft.Xna.Framework.Graphics;
  5. namespace BackgroundThreadTester
  6. {
  7. public class Object : Microsoft.Xna.Framework.DrawableGameComponent
  8. {
  9. public Vector2 pos;
  10. protected Texture2D texture;
  11. private Vector2 v2Temp;
  12. protected Rectangle recCurrentFrame;
  13. public int nAlpha;
  14. public float fRotation;
  15. public Vector2 vecRotationCenter;
  16. private List<Rectangle> frames;
  17. public Object(Game game, ref Texture2D theTexture)
  18. : base(game)
  19. {
  20. texture = theTexture;
  21. v2Temp = new Vector2();
  22. fRotation = 0;
  23. pos = new Vector2();
  24. pos.X = 0;
  25. pos.Y = 0;
  26. vecRotationCenter.X = 0;
  27. vecRotationCenter.Y = 0;
  28. Frames = new List<Rectangle>();
  29. Rectangle frame = new Rectangle();
  30. //Extract the frames from the texture
  31. frame.X = 0;
  32. frame.Y = 0;
  33. frame.Width = texture.Width;
  34. frame.Height = texture.Height;
  35. Frames.Add(frame);
  36. }
  37. public override void Update(GameTime gameTime)
  38. {
  39. recCurrentFrame = frames[0];
  40. base.Update(gameTime);
  41. }
  42. public override void Draw(GameTime gameTime)
  43. {
  44. v2Temp.X = pos.X - (texture.Width / 2);
  45. v2Temp.Y = pos.Y - texture.Height;
  46. // Get the current spritebatch
  47. SpriteBatch sBatch = (SpriteBatch)Game.Services.GetService(typeof(SpriteBatch));
  48. sBatch.Draw(texture, v2Temp, recCurrentFrame, new Color(255, 255, 255, nAlpha), fRotation, vecRotationCenter, 1f, SpriteEffects.None, 0);
  49. base.Draw(gameTime);
  50. }
  51. public List<Rectangle> Frames
  52. {
  53. get { return frames; }
  54. set { frames = value; }
  55. }//Frames
  56. }
  57. }