Lines.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Microsoft.Xna.Framework;
  6. using Microsoft.Xna.Framework.Graphics;
  7. namespace StarWarrior.Primitives
  8. {
  9. public class Lines
  10. {
  11. PrimitiveBatch batch;
  12. List<Vector2> lines = new List<Vector2>();
  13. Color color = Color.White;
  14. GraphicsDevice device;
  15. public Lines(GraphicsDevice device,PrimitiveBatch primitiveBatch)
  16. {
  17. this.device = device;
  18. this.batch = primitiveBatch;
  19. }
  20. public void AddLine(float x1, float y1, float x2, float y2)
  21. {
  22. lines.Add(new Vector2(x1,y1));
  23. lines.Add(new Vector2(x2, y2));
  24. }
  25. public void SetColor(Color color)
  26. {
  27. this.color = color;
  28. }
  29. public void Draw(Vector2 transform)
  30. {
  31. batch.Begin(PrimitiveType.LineList);
  32. foreach (var item in lines)
  33. {
  34. batch.AddVertex(item + transform, color);
  35. }
  36. batch.End();
  37. }
  38. }
  39. }