public override void Draw(GameTime gameTime) { batch.Begin(PrimitiveType.TriangleList); batch.AddVertex(new Vector2(Bounds.Left, Bounds.Bottom), BackgroundColor); batch.AddVertex(new Vector2(Bounds.Left, Bounds.Top), BackgroundColor); batch.AddVertex(new Vector2(Bounds.Right, Bounds.Top), BackgroundColor); batch.AddVertex(new Vector2(Bounds.Right, Bounds.Bottom), BackgroundColor); batch.AddVertex(new Vector2(Bounds.Left, Bounds.Bottom), BackgroundColor); batch.AddVertex(new Vector2(Bounds.Right, Bounds.Top), BackgroundColor); batch.End(); //rad dropshadow batch.Begin(PrimitiveType.LineList); batch.AddVertex(new Vector2(Bounds.Left, Bounds.Bottom), Color.Black); batch.AddVertex(new Vector2(Bounds.Right, Bounds.Bottom), Color.Black); batch.AddVertex(new Vector2(Bounds.Right, Bounds.Top), Color.Black); batch.AddVertex(new Vector2(Bounds.Right, Bounds.Bottom + 1), Color.Black); batch.End(); textBatch.Begin(); textBatch.DrawString(font, caption, textPosition, ForegroundColor); textBatch.End(); // batch.AddVertex( base.Draw(gameTime); }
public void Draw(PrimitiveBatch batch) { batch.Begin(PrimitiveType.LineList); for (int i = 0; i < transformedVertices.Length; i++) { batch.AddVertex(transformedVertices[i], ShapeColor); batch.AddVertex(transformedVertices[ (i + 1) % transformedVertices.Length], ShapeColor); } batch.End(); }
//TODO: draw the bounding box at the same time //this means moving the bounding box drawing code out of the //staticbody class and into the bounding rectangle, so you can just go //BoundingRectangle.Draw(); public override void Draw(GameTime gameTime) { if (game.state != GameState.gsEdit) { return; } Vector2 mousePos = new Vector2(Mouse.GetState().X, Mouse.GetState().Y); edgeBatch.Begin(PrimitiveType.LineList); vertexBatch.Begin(PrimitiveType.PointList); int i; for (i = 0; i < shape.Count; i++) { edgeBatch.AddVertex(shape[i], Color.Green); edgeBatch.AddVertex(shape[i + (i == (shape.Count - 1) ? 0 : 1)], Color.Green); vertexBatch.AddVertex(shape[i], Color.Yellow); } if (makingShape && shape.Count > 0) { edgeBatch.AddVertex(shape[i - 1], Color.Green); edgeBatch.AddVertex(mousePos, Color.Yellow); } vertexBatch.End(); edgeBatch.End(); if (makingShape && shape.Count > 1) { if (Vector2.Distance(mousePos, shape[0]) < 10f) { finishText.Begin(); finishText.DrawString(finishFont, "Finish Shape", mousePos, Color.Blue); finishText.End(); finishShape = true; } else { finishShape = false; } } base.Draw(gameTime); }
/// <summary> /// Draws the static body /// </summary> /// public virtual void Draw() { // Rotation Disabled for Static Shapes /*if (Keyboard.GetState().IsKeyDown(Keys.Left)) * { * angle = 0.01f; * //angle = MathHelper.Clamp(angle, -360, 360); * Rotate(angle); * } * else if (Keyboard.GetState().IsKeyDown(Keys.Right)) * { * angle = -0.01f; * //angle = MathHelper.Clamp(angle, -360, 360); * Rotate(angle); * }*/ //show bounding box if (Keyboard.GetState().IsKeyDown(Keys.B)) { batch.Begin(PrimitiveType.LineList); //top line batch.AddVertex(new Vector2(BoundingBox.l, BoundingBox.t), Color.Green); batch.AddVertex(new Vector2(BoundingBox.r, BoundingBox.t), Color.Green); //left line batch.AddVertex(new Vector2(BoundingBox.l, BoundingBox.t), Color.Green); batch.AddVertex(new Vector2(BoundingBox.l, BoundingBox.b), Color.Green); //right line batch.AddVertex(new Vector2(BoundingBox.r, BoundingBox.t), Color.Green); batch.AddVertex(new Vector2(BoundingBox.r, BoundingBox.b), Color.Green); //bottom line batch.AddVertex(new Vector2(BoundingBox.l, BoundingBox.b), Color.Green); batch.AddVertex(new Vector2(BoundingBox.r, BoundingBox.b), Color.Green); batch.End(); } graphics.VertexDeclaration = vertDecl; graphics.Indices = indexBuffer; graphics.Vertices[0].SetSource(vertBuffer, 0, VertexPositionColor.SizeInBytes); // if holding 'W' key, render in wireframe if (Keyboard.GetState().IsKeyDown(Keys.W)) { graphics.RenderState.FillMode = FillMode.WireFrame; } else { graphics.RenderState.FillMode = FillMode.Solid; } effect.Begin(); effect.World = Matrix.CreateTranslation(new Vector3(GetScreenPosition(), 0)); foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Begin(); graphics.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, numVertices, 0, numPrimitives); pass.End(); } effect.End(); }