protected override void OnRender(IImmutableSpriteBatch spriteBatch, ref Rectangle boundingRectangle) { spriteBatch.Draw( _texture, _bullet.Position * _scale, null, null, _bodyTextureCenter, //origin _bullet.Rotation); }
protected override void OnRender(IImmutableSpriteBatch spriteBatch, ref Rectangle boundingRectangle) { spriteBatch.Draw( _bodyTexture, _tank.Position * _scale, //position null, //destinationRectangle null, //sourceRectangle _bodyTextureCenter, //origin _tank.Rotation + (float)Math.PI / 2); //color spriteBatch.Draw( _towerTexture, _tank.Tower.Position * _scale, //position null, //destinationRectangle null, //sourceRectangle _towerTextureCenter, //origin _tank.Tower.Rotation + (float)Math.PI / 2); //color }
/// <summary> /// Method to draw a MapObject that represents a tile object /// </summary> /// <param name="spriteBatch">XNA SpriteBatch instance; SpriteBatch.Begin() must be called before using this method</param> /// <param name="objectLayerId">Index of the layer to draw in the Map.ObjectLayers collection</param> /// <param name="objectId">Index of the object to draw in the Map.ObjectLayers.MapObjects collection</param> /// <param name="region">Region of the map in pixels to draw</param> /// <param name="layerDepth">LayerDepth value to pass to SpriteBatch</param> /// <param name="color">Color of the object</param> public void DrawTileObject(IImmutableSpriteBatch spriteBatch, int objectLayerId, int objectId, ref Rectangle region, float layerDepth, ref Color color) { spriteBatch.Draw( Tilesets[SourceTiles[ObjectLayers[objectLayerId].MapObjects[objectId].TileId.Value].TilesetId].Texture, Translate(ObjectLayers[objectLayerId].MapObjects[objectId].Bounds, region), SourceTiles[ObjectLayers[objectLayerId].MapObjects[objectId].TileId.Value].Source, color, 0, SourceTiles[ObjectLayers[objectLayerId].MapObjects[objectId].TileId.Value].Origin, SpriteEffects.None, layerDepth); }
/// <summary> /// Method to draw a MapObject that represents a tile object /// </summary> /// <param name="spriteBatch">XNA SpriteBatch instance; SpriteBatch.Begin() must be called before using this method</param> /// <param name="objectLayerId">Index of the layer to draw in the Map.ObjectLayers collection</param> /// <param name="objectId">Index of the object to draw in the Map.ObjectLayers.MapObjects collection</param> /// <param name="region">Region of the map in pixels to draw</param> /// <param name="layerDepth">LayerDepth value to pass to SpriteBatch</param> /// <param name="color">Color of the object</param> public void DrawTileObject(IImmutableSpriteBatch spriteBatch, int objectLayerId, int objectId, Rectangle region, float layerDepth, Color color) { DrawTileObject(spriteBatch, objectLayerId, objectId, ref region, layerDepth, ref color); }
/// <summary> /// Draws all objects on the given object layer /// </summary> /// <param name="spriteBatch">XNA SpriteBatch instance; SpriteBatch.Begin() must be called before using this method</param> /// <param name="objectLayerId">Index of the layer to draw in the Map.ObjectLayers collection</param> /// <param name="region">Region of the map in pixels to draw</param> /// <param name="layerDepth">LayerDepth value to pass to SpriteBatch</param> public void DrawObjectLayer(IImmutableSpriteBatch spriteBatch, int objectLayerId, ref Rectangle region, float layerDepth) { if (WhiteTexture == null) { throw new Exception("Map.InitObjectDrawing must be called before Map is loaded to enable object rendering"); } for (var o = 0; o < ObjectLayers[objectLayerId].MapObjects.Length; o++) if (region.Contains(ObjectLayers[objectLayerId].MapObjects[o].Bounds) || region.Intersects(ObjectLayers[objectLayerId].MapObjects[o].Bounds)) DrawMapObject(spriteBatch, objectLayerId, o, ref region, layerDepth); }
/// <summary> /// Draws all objects on the given object layer /// </summary> /// <param name="spriteBatch">XNA SpriteBatch instance; SpriteBatch.Begin() must be called before using this method</param> /// <param name="objectLayerId">Index of the layer to draw in the Map.ObjectLayers collection</param> /// <param name="region">Region of the map in pixels to draw</param> /// <param name="layerDepth">LayerDepth value to pass to SpriteBatch</param> public void DrawObjectLayer(IImmutableSpriteBatch spriteBatch, int objectLayerId, Rectangle region, float layerDepth) { DrawObjectLayer(spriteBatch, objectLayerId, ref region, layerDepth); }
/// <summary> /// Method to draw a MapObject /// </summary> /// <param name="spriteBatch">XNA SpriteBatch instance; SpriteBatch.Begin() must be called before using this method</param> /// <param name="objectLayerId">Index of the layer to draw in the Map.ObjectLayers collection</param> /// <param name="objectId">Index of the object to draw in the Map.ObjectLayers.MapObjects collection</param> /// <param name="region">Region of the map in pixels to draw</param> /// <param name="layerDepth">LayerDepth value to pass to SpriteBatch</param> public void DrawMapObject(IImmutableSpriteBatch spriteBatch, int objectLayerId, int objectId, ref Rectangle region, float layerDepth) { var color = ObjectLayers[objectLayerId].Color ?? ObjectLayers[objectLayerId].OpacityColor; var fillColor = color; fillColor.A /= 4; if (ObjectLayers[objectLayerId].MapObjects[objectId].Polyline != null) ObjectLayers[objectLayerId].MapObjects[objectId].Polyline.Draw(spriteBatch, region, WhiteTexture, LineThickness, color, layerDepth); else if (ObjectLayers[objectLayerId].MapObjects[objectId].Polygon != null) ObjectLayers[objectLayerId].MapObjects[objectId].Polygon.DrawFilled(spriteBatch, region, WhiteTexture, LineThickness, color, fillColor, layerDepth); else if (ObjectLayers[objectLayerId].MapObjects[objectId].TileId.HasValue) DrawTileObject(spriteBatch, objectLayerId, objectId, ref region, layerDepth, ref color); else DrawRectangle(spriteBatch, ref ObjectLayers[objectLayerId].MapObjects[objectId].Bounds, ref region, layerDepth, ref color, ref fillColor); }
protected virtual void OnRender(IImmutableSpriteBatch spriteBatch, ref Rectangle boundingRectangle) { }
protected override void OnRender(IImmutableSpriteBatch spriteBatch, ref Rectangle boundingRectangle) { _map.Draw(spriteBatch, boundingRectangle); }
/// <summary> /// Draws all visible tile layers /// </summary> /// <param name="spriteBatch">XNA SpriteBatch instance; SpriteBatch.Begin() must be called before using this method</param> /// <param name="region">Region of the map in pixels to draw</param> /// <param name="drawHiddenLayers">If true, draws layers regardless of TileLayer.Visible flag</param> public void Draw(IImmutableSpriteBatch spriteBatch, Rectangle region, bool drawHiddenLayers, float layerDepth = 0f) { Draw(spriteBatch, ref region, drawHiddenLayers, layerDepth); }
/// <summary> /// Draws all visible tile layers /// </summary> /// <param name="spriteBatch">XNA SpriteBatch instance; SpriteBatch.Begin() must be called before using this method</param> /// <param name="region">Region of the map in pixels to draw</param> public void Draw(IImmutableSpriteBatch spriteBatch, ref Rectangle region, float layerDepth = 0f) { Draw(spriteBatch, ref region, false, layerDepth); }
/// <summary> /// Method to draw a Rectangle /// </summary> /// <param name="spriteBatch">XNA SpriteBatch instance; SpriteBatch.Begin() must be called before using this method</param> /// <param name="rect">The Rectangle to draw, in map pixels</param> /// <param name="region">Region of the map in pixels currently visible</param> /// <param name="layerDepth">LayerDepth value to pass to SpriteBatch</param> /// <param name="linecolor">Color of the Rectangle border</param> /// <param name="fillColor">Color to fill the Rectangle with</param> public static void DrawRectangle(IImmutableSpriteBatch spriteBatch, ref Rectangle rect, ref Rectangle region, float layerDepth, ref Color linecolor, ref Color fillColor) { if (WhiteTexture == null) { throw new Exception("Map.InitObjectDrawing must be called before Map is loaded to enable object rendering"); } var target = Translate(rect, region); spriteBatch.Draw(WhiteTexture, target, null, fillColor, 0, Vector2.Zero, SpriteEffects.None, layerDepth); Line.Draw(spriteBatch, Line.FromPoints(new Vector2(rect.Right, rect.Top), new Vector2(rect.Left, rect.Top)), region, WhiteTexture, LineThickness, linecolor, layerDepth); Line.Draw(spriteBatch, Line.FromPoints(new Vector2(rect.Left, rect.Top), new Vector2(rect.Left, rect.Bottom)), region, WhiteTexture, LineThickness, linecolor, layerDepth); Line.Draw(spriteBatch, Line.FromPoints(new Vector2(rect.Left, rect.Bottom), new Vector2(rect.Right, rect.Bottom)), region, WhiteTexture, LineThickness, linecolor, layerDepth); Line.Draw(spriteBatch, Line.FromPoints(new Vector2(rect.Right, rect.Bottom), new Vector2(rect.Right, rect.Top)), region, WhiteTexture, LineThickness, linecolor, layerDepth); }
/// <summary> /// Method to draw a Rectangle /// </summary> /// <param name="spriteBatch">XNA SpriteBatch instance; SpriteBatch.Begin() must be called before using this method</param> /// <param name="rect">The Rectangle to draw, in map pixels</param> /// <param name="region">Region of the map in pixels currently visible</param> /// <param name="layerDepth">LayerDepth value to pass to SpriteBatch</param> /// <param name="linecolor">Color of the Rectangle border</param> /// <param name="fillColor">Color to fill the Rectangle with</param> public static void DrawRectangle(IImmutableSpriteBatch spriteBatch, Rectangle rect, Rectangle region, float layerDepth, Color linecolor, Color fillColor) { DrawRectangle(spriteBatch, ref rect, ref region, layerDepth, ref linecolor, ref fillColor); }
/// <summary> /// Draws a Line /// </summary> /// <param name="spriteBatch">XNA SpriteBatch instance; SpriteBatch.Begin() must be called before using this method</param> /// <param name="line">The Line to draw</param> /// <param name="region">Region of the map in pixels to draw</param> /// <param name="texture">A texture to use in drawing the line</param> /// <param name="lineWidth">The width of the line in pixels</param> /// <param name="color">The color value to apply to the given texture</param> /// <param name="layerDepth">LayerDepth value to pass to SpriteBatch</param> public static void Draw(IImmutableSpriteBatch spriteBatch, Line line, Rectangle region, Texture2D texture, float lineWidth, Color color, float layerDepth) { var start = Map.Translate(line.Start, region); spriteBatch.Draw(texture, start, null, color, line.Angle, Vector2.Zero, new Vector2(line.Length, lineWidth), SpriteEffects.None, layerDepth); }
private void DrawLayer(IImmutableSpriteBatch spriteBatch, int layerId, ref Rectangle region, int txMin, int txMax, int tyMin, int tyMax, float layerDepth) { for (var y = tyMin; y <= tyMax; y++) { for (var x = txMin; x <= txMax; x++) { if (x >= TileLayers[layerId].Tiles.Length || y >= TileLayers[layerId].Tiles[x].Length || TileLayers[layerId].Tiles[x][y] == null) continue; var tileTarget = TileLayers[layerId].Tiles[x][y].Target; tileTarget.X = tileTarget.X - region.X; tileTarget.Y = tileTarget.Y - region.Y; spriteBatch.Draw( Tilesets[SourceTiles[TileLayers[layerId].Tiles[x][y].SourceId].TilesetId].Texture, tileTarget, SourceTiles[TileLayers[layerId].Tiles[x][y].SourceId].Source, TileLayers[layerId].OpacityColor, TileLayers[layerId].Tiles[x][y].Rotation, SourceTiles[TileLayers[layerId].Tiles[x][y].SourceId].Origin, TileLayers[layerId].Tiles[x][y].Effects, layerDepth); } } }
/// <summary> /// Draws the lines that make up the Polyline /// </summary> /// <param name="spriteBatch">XNA SpriteBatch instance; SpriteBatch.Begin() must be called before using this method</param> /// <param name="region">Region of the map in pixels to draw</param> /// <param name="texture">A texture to use in drawing the lines</param> /// <param name="lineWidth">The width of the lines in pixels</param> /// <param name="color">The color value to apply to the given texture</param> /// <param name="layerDepth">LayerDepth value to pass to SpriteBatch</param> public void Draw(IImmutableSpriteBatch spriteBatch, Rectangle region, Texture2D texture, float lineWidth, Color color, float layerDepth) { foreach (var line in Lines) Line.Draw(spriteBatch, line, region, texture, lineWidth, color, layerDepth); }
/// <summary> /// Draws all visible tile layers /// </summary> /// <param name="spriteBatch">XNA SpriteBatch instance; SpriteBatch.Begin() must be called before using this method</param> /// <param name="region">Region of the map in pixels to draw</param> /// <param name="drawHiddenLayers">If true, draws layers regardless of TileLayer.Visible flag</param> public void Draw(IImmutableSpriteBatch spriteBatch, ref Rectangle region, bool drawHiddenLayers, float layerDepth = 0) { var txMin = region.X / TileWidth; var txMax = (region.X + region.Width) / TileWidth; var tyMin = region.Y / TileHeight; var tyMax = (region.Y + region.Height) / TileHeight; if (Orientation == MapOrientation.Isometric) { tyMax = tyMax * 2 + 1; txMax = txMax * 2 + 1; } for (var l = 0; l < TileLayers.Count; l++) if (TileLayers[l].Visible || drawHiddenLayers) DrawLayer(spriteBatch, l, ref region, txMin, txMax, tyMin, tyMax, layerDepth); }
/// <summary> /// Draws given tile layer /// </summary> /// <param name="spriteBatch">XNA SpriteBatch instance; SpriteBatch.Begin() must be called before using this method</param> /// <param name="layerId">Index of the layer to draw in the Map.TileLayers collection</param> /// <param name="region">Region of the map in pixels to draw</param> /// <param name="layerDepth">LayerDepth value to pass to SpriteBatch</param> public void DrawLayer(IImmutableSpriteBatch spriteBatch, int layerId, ref Rectangle region, float layerDepth) { var txMin = region.X / TileWidth; var txMax = (region.X + region.Width) / TileWidth; var tyMin = region.Y / TileHeight; var tyMax = (region.Y + region.Height) / TileHeight; if (Orientation == MapOrientation.Isometric) { tyMax = tyMax * 2 + 1; txMax = txMax * 2 + 1; } DrawLayer(spriteBatch, layerId, ref region, txMin, txMax, tyMin, tyMax, layerDepth); }
public void Render(IImmutableSpriteBatch spriteBatch, ref Rectangle boundingRectangle) { if (IsDestroyed) throw new InvalidOperationException("Cannot render destroyed view"); OnRender(spriteBatch, ref boundingRectangle); }