public override void Draw(IDrawContext drawContext, DrawingLayer drawingLayer) { var finalFrom = drawingLayer.CameraMode == CameraMode.Fix ? this.FromVector : this.FromVector .Scale(drawContext.Camera.ZoomFactor) .Translate(drawContext.Camera.GetSceneTranslationVector(drawingLayer.ParallaxScrollingVector)); var finalTo = drawingLayer.CameraMode == CameraMode.Fix ? this.ToVector : this.ToVector .Scale(drawContext.Camera.ZoomFactor) .Translate(drawContext.Camera.GetSceneTranslationVector(drawingLayer.ParallaxScrollingVector)); var zoom = drawingLayer.CameraMode == CameraMode.Fix ? 1.0f : this.Width * drawContext.Camera.ZoomFactor; //var finalWidth = this.width * camera.ZoomFactor; //var angle = (float)Math.Atan2(finalTo.Y - finalFrom.Y, finalTo.X - finalFrom.X); //var length = Vector.Distance(finalFrom, finalTo); var param = new DrawLineParams { VectorFrom = finalFrom, VectorTo = finalTo, Width = zoom, Color = this.Color }; drawContext.DrawLine(param); //spriteBatch.Draw(this.blank, finalFrom, null, this.color, angle, Vector.Zero, // new Vector(length, finalWidth), SpriteEffects.None, 0); }
public static DrawingLayer DrawingLayerFromXml(XElement layerElement) { var name = layerElement.Attribute("name").Value; var layer = new DrawingLayer(name); XmlRepository.BaseFromXml(layer, layerElement); foreach (var element in layerElement.Element("Elements").Elements()) { switch (element.Name.ToString()) { case "TextElement": layer.AddElement(TextElementFromXml(element)); break; case "LineElement": layer.AddElement(LineElementFromXml(element)); break; case "PolygonElement": layer.AddElement(PolygonElementFromXml(element)); break; default: throw new NotImplementedException(element.Name + " is not implemented yet."); } } return layer; }
public override void Draw(IDrawContext drawContext, DrawingLayer drawingLayer) { var topLeft = new Vector(this.x, this.y); var topRight = new Vector(this.x + this.width, this.y); var bottomLeft = new Vector(this.x, this.y + this.height); var bottomRight = new Vector(this.x + this.width, this.y + this.height); this.DrawLine(drawContext, drawingLayer, topLeft, topRight, this.LineWidth, this.Color); this.DrawLine(drawContext, drawingLayer, topRight, bottomRight, this.LineWidth, this.Color); this.DrawLine(drawContext, drawingLayer, bottomRight, bottomLeft, this.LineWidth, this.Color); this.DrawLine(drawContext, drawingLayer, bottomLeft, topLeft, this.LineWidth, this.Color); }
protected override Scene CreateScene() { var scene = new Scene("Tiled") { UseLinearSampler = false }; scene.Add(new ColorLayer("Background", Color.CornflowerBlue)); var tiledFile = TiledFile.LoadScalable(@"Tiled\untitled.tmx", this.ResourceManager); this.tileLayers = tiledFile.TileLayers.ToList(); scene.AddRange(this.tileLayers); var drawingLayer = new DrawingLayer("ObjectLayer"); foreach (var tiledObject in tiledFile.ObjectLayers.First().TiledObjects) drawingLayer.AddRectangle(tiledObject.Position.X, tiledObject.Position.Y, 10, 10, 2, Color.Red); scene.Add(drawingLayer); return scene; }
protected void DrawLine(IDrawContext drawContext, DrawingLayer drawingLayer, Vector fromVector, Vector toVector, int width, Color color) { var finalFrom = fromVector .Scale(drawContext.Camera.ZoomFactor) .Translate(drawContext.Camera.GetSceneTranslationVector(drawingLayer.ParallaxScrollingVector)); var finalTo = toVector .Scale(drawContext.Camera.ZoomFactor) .Translate(drawContext.Camera.GetSceneTranslationVector(drawingLayer.ParallaxScrollingVector)); var param = new DrawLineParams { VectorFrom = finalFrom, VectorTo = finalTo, Width = width * drawContext.Camera.ZoomFactor, Color = color }; drawContext.DrawLine(param); }
public override void Draw(IDrawContext drawContext, DrawingLayer drawingLayer) { var finalText = this.Parameters != null ? string.Format(this.Text, this.Parameters) : this.Text; var finalZoomFactor = drawingLayer.CameraMode == CameraMode.Fix ? 1.0f : drawContext.Camera.ZoomFactor; var finalVector = drawingLayer.CameraMode == CameraMode.Fix ? this.Position : this.Position .Scale(drawContext.Camera.ZoomFactor) .Translate(drawContext.Camera.GetSceneTranslationVector(drawingLayer.ParallaxScrollingVector)); var param = new DrawStringParams { Text = finalText, Vector = finalVector, ZoomFactor = finalZoomFactor, DrawingFont = this.DrawingFont, Color = this.Color }; drawContext.DrawString(param); }
public abstract void Draw(IDrawContext drawContext, DrawingLayer drawingLayer);
public static XElement ToXml(DrawingLayer drawingLayer) { return new XElement("DrawingLayer", XmlRepository.LayerBaseToXml(drawingLayer), new XElement("Elements", drawingLayer.Elements.Select(ToXml))); }
protected override Scene CreateScene() { var scene = new Scene("HubScene"); scene.Add(new ColorLayer("Background", Color.CornflowerBlue)); var font = this.ResourceManager.GetDrawingFont(@"Sandbox\SpriteFont1"); var hubMap = new DrawingLayer("HubMap"); this.sandboxRectangle = hubMap.AddRectangle(10, 10, 200, 200, 1, Color.White); this.shootEmUpRectangle = hubMap.AddRectangle(220, 10, 200, 200, 1, Color.White); this.tiledRectangle = hubMap.AddRectangle(10, 230, 200, 200, 1, Color.White); this.touchRectangle = hubMap.AddRectangle(220, 230, 200, 200, 1, Color.White); //hubMap.AddRectangle(10, 230, 200, 200, 1, Color.White); //hubMap.AddRectangle(220, 230, 200, 200, 1, Color.White); hubMap.AddText(font, "1 - Sandbox sample", new Vector(20, 210), Color.White); hubMap.AddText(font, "2 - ShootEmUp sample", new Vector(220, 210), Color.White); hubMap.AddText(font, "3 - Tiled sample", new Vector(20, 430), Color.White); hubMap.AddText(font, "4 - Touch sample", new Vector(220, 430), Color.White); scene.Add(hubMap); scene.Add(new MouseCursor(this.InputConfiguration.CreateMouseTracking(this.Camera))); return scene; }
private DrawingLayer CreateButtonLayer() { var font = this.ResourceManager.GetDrawingFont(@"Sandbox\SpriteFont1"); var drawingMap = new DrawingLayer("Button"); this.visualBackButtonElement = drawingMap.AddRectangle(this.visualBackButton.Rectangle, 2, Color.Blue); drawingMap.AddText(font, "Back", this.visualBackButton.Rectangle.Location.Translate(10, 10), Color.White); return drawingMap; }
public override void Draw(IDrawContext drawContext, DrawingLayer drawingLayer) { this.Vertices.ForEachPair((x, y) => this.DrawLine(drawContext, drawingLayer, x, y, this.Width, this.Color)); }
private DrawingLayer CreateHexLayerTestDistance() { var layer = new DrawingLayer("Hex drawing test"); var font = this.ResourceManager.GetDrawingFont(@"Sandbox\SpriteFont1"); var hexMap = HexGrid.CreateHexMap(30, 9); foreach (var hex in hexMap.Hexes) { var distance = HexGrid.HexDistance(hexMap[4, 5], hex); var color = distance == 1 ? new Color(0, 255, 0, 255) : distance == 2 ? new Color(0, 192, 0, 255) : distance == 3 ? new Color(0, 128, 0, 255) : distance == 4 ? new Color(0, 64, 0, 255) : distance == 5 ? new Color(128, 0, 128, 255) : Color.Red; layer.AddPolygone(3, color, hex.GetVertices()); var text = string.Format("{0},{1}", hex.Position.X - 4, hex.Position.Y - 5 + (hex.Position.X % 2) * .5); var measure = font.MeasureString(text); layer.AddText(font, text, hex.Center - (measure / 2.0f), Color.Yellow); } this.layer = layer; return layer; }