private void DrawItem(LineListMesh lineList) { if (lineList != null && lineList.Lines != null) { var vertices = lineList.Lines; int vertexCount = vertices.Length / 2 * 2; if (this.D2DEnabled) { Prepare(ItemType.D2DObject); for (int i = 0; i < vertexCount; i += 2) { this.d2dRender.DrawLine(vertices[i].ToVector2(), vertices[i + 1].ToVector2(), lineList.Thickness, lineList.Color); } } else { Prepare(ItemType.Sprite); for (int i = 0; i < vertexCount; i += 2) { sprite.DrawLine(vertices[i], vertices[i + 1], lineList.Thickness, lineList.Color); } } } }
private void DrawItem(LineListMesh lineList) { if (lineList != null && lineList.Lines != null) { var vertices = lineList.Lines; for (int i = 0, i1 = vertices.Length / 2 * 2; i < i1; i += 2) { sprite.DrawLine(vertices[i], vertices[i + 1], lineList.Thickness, lineList.Color); } } }
public void Draw(SpriteBatch sb) { DrawSquare(Game1.Instance.GraphicsDevice); sb.Begin(); SpriteBatchEx.DrawLine(sb, PointA, PointB, Color.Black, 1); SpriteBatchEx.DrawLine(sb, PointB, PointD, Color.Black, 1); SpriteBatchEx.DrawLine(sb, PointD, PointC, Color.Black, 1); SpriteBatchEx.DrawLine(sb, PointC, PointA, Color.Black, 1); sb.End(); //Vector2[] Points = new Vector2[4] { PointA, PointB, PointD, PointC }; //SpriteBatchEx.DrawPolyLine(sb, Points, Color, 3, true); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Gray); spriteBatch.Begin(); GameManager.GM.sb = spriteBatch; // TODO: Add your drawing code here //draw menu if (GUIManager.GuiManager.state == (int)GUIManager.GameState.menu) { Menu.M.Draw(Menu.M.MainMenu); } //draw objects else if (GUIManager.GuiManager.state == (int)GUIManager.GameState.play) { //draw every object foreach (Object o in GameManager.GM.objects) { spriteBatch.Draw(texture: o.tex, position: o.pos, destinationRectangle: null, sourceRectangle: null, origin: new Vector2(o.tex.Width / 2, o.tex.Height / 2), rotation: o.rot.Z, scale: null, color: null, layerDepth: 0); } //draw tiles and there reset is debug stuff foreach (KeyValuePair <Guid, PhysicsObject> o in Physics.Phy.physicsObjects) { //draw aabb if ((o.Value.GetType().IsAssignableFrom(typeof(Rect)) || o.Value.GetType().IsSubclassOf(typeof(Rect))) && debug) { Rect ro = (Rect)o.Value; ro.GetPoints(); SpriteBatchEx.DrawLine(spriteBatch, new Vector2(ro.aabb.Location.X, ro.aabb.Location.Y), new Vector2(ro.aabb.Location.X + ro.aabb.Width, ro.aabb.Location.Y), Color.White); SpriteBatchEx.DrawLine(spriteBatch, new Vector2(ro.aabb.Location.X + ro.aabb.Width, ro.aabb.Location.Y), new Vector2(ro.aabb.Location.X + ro.aabb.Width, ro.aabb.Location.Y + ro.aabb.Height), Color.White); SpriteBatchEx.DrawLine(spriteBatch, new Vector2(ro.aabb.Location.X + ro.aabb.Width, ro.aabb.Location.Y + ro.aabb.Height), new Vector2(ro.aabb.Location.X, ro.aabb.Location.Y + ro.aabb.Height), Color.White); SpriteBatchEx.DrawLine(spriteBatch, new Vector2(ro.aabb.Location.X, ro.aabb.Location.Y + ro.aabb.Height), new Vector2(ro.aabb.Location.X, ro.aabb.Location.Y), Color.White); Vector2[] tpoints = new Vector2[ro.points.Length]; for (int i = 0; i < ro.points.Length; i++) { tpoints[i] = ro.GetPointAfterRotation(new Vector2(ro.points[i].X, ro.points[i].Y)); } for (int i = 0; i < ro.points.Length; i++) { if (i == ro.points.Length - 1) { SpriteBatchEx.DrawLine(spriteBatch, new Vector2(tpoints[0].X, tpoints[0].Y), new Vector2(tpoints[i].X, tpoints[i].Y), Color.Black); } else { SpriteBatchEx.DrawLine(spriteBatch, new Vector2(tpoints[i + 1].X, tpoints[i + 1].Y), new Vector2(tpoints[i].X, tpoints[i].Y), Color.Black); } } } else if ((o.Value.GetType().IsAssignableFrom(typeof(Circle)) || o.Value.GetType().IsSubclassOf(typeof(Circle))) && debug) { Circle c = (Circle)o.Value; Texture2D circle = SpriteBatchEx.CreateCircle((int)c.radius); spriteBatch.Draw(circle, new Vector2(c.pos.X - circle.Width / 2, c.pos.Y - circle.Height / 2), Color.Red); } } if (debug) { foreach (KeyValuePair <int, NavTile> t in GameManager.GM.currentLevel.nav) { SpriteBatchEx.DrawLine(spriteBatch, new Vector2(t.Value.pos.X - Level.tilesize / 2, t.Value.pos.Y - Level.tilesize / 2), new Vector2(t.Value.pos.X + Level.tilesize / 2, t.Value.pos.Y - Level.tilesize / 2), Color.Green); SpriteBatchEx.DrawLine(spriteBatch, new Vector2(t.Value.pos.X + Level.tilesize / 2, t.Value.pos.Y - Level.tilesize / 2), new Vector2(t.Value.pos.X + Level.tilesize / 2, t.Value.pos.Y + Level.tilesize / 2), Color.Green); SpriteBatchEx.DrawLine(spriteBatch, new Vector2(t.Value.pos.X + Level.tilesize / 2, t.Value.pos.Y + Level.tilesize / 2), new Vector2(t.Value.pos.X - Level.tilesize / 2, t.Value.pos.Y + Level.tilesize / 2), Color.Green); SpriteBatchEx.DrawLine(spriteBatch, new Vector2(t.Value.pos.X - Level.tilesize / 2, t.Value.pos.Y + Level.tilesize / 2), new Vector2(t.Value.pos.X - Level.tilesize / 2, t.Value.pos.Y - Level.tilesize / 2), Color.Green); spriteBatch.DrawString(font, t.Key.ToString(), new Vector2(t.Value.pos.X, t.Value.pos.Y), Color.Green); } foreach (PhysicsSystem ps in GameManager.GM.currentLevel.LevelPhysics) { SpriteBatchEx.DrawLine(spriteBatch, new Vector2(ps.area.Left, ps.area.Top), new Vector2(ps.area.Right, ps.area.Top), Color.Blue); SpriteBatchEx.DrawLine(spriteBatch, new Vector2(ps.area.Right, ps.area.Top), new Vector2(ps.area.Right, ps.area.Bottom), Color.Blue); SpriteBatchEx.DrawLine(spriteBatch, new Vector2(ps.area.Right, ps.area.Bottom), new Vector2(ps.area.Left, ps.area.Bottom), Color.Blue); SpriteBatchEx.DrawLine(spriteBatch, new Vector2(ps.area.Left, ps.area.Bottom), new Vector2(ps.area.Left, ps.area.Top), Color.Blue); } } base.Draw(gameTime); //draw score spriteBatch.DrawString(font, "Score: " + GameManager.GM.score, new Vector2(700, 650), Color.Red); } spriteBatch.End(); }