Object.cs 2.3 KB

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