Translate() public static method

Translates a location to screen space
public static Translate ( Point location, Rectangle relativeTo ) : Point
location Point The location in map pixel coordinates
relativeTo Rectangle Region of the map that is on screen
return Point
Example #1
0
        /// <summary>
        /// Method to draw a MapImage
        /// </summary>
        /// <param name="spriteBatch">XNA SpriteBatch instance; SpriteBatch.Begin() must be called before using this method</param>
        /// <param name="imageLayerID">Index of the layer to draw in the Map.ImageLayers collection</param>
        /// <param name="imageID">Index of the object to draw in the Map.ImageLayers.MapImages collection</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>
        public void DrawMapImage(SpriteBatch spriteBatch, Int32 imageLayerID, Int32 imageID, ref Rectangle rect, ref Rectangle region, Single layerDepth)
        {
            Color     color  = this.ImageLayers[imageLayerID].Color ?? this.ImageLayers[imageLayerID].OpacityColor;
            Rectangle target = Map.Translate(rect, region);

            spriteBatch.Draw(this.ImageLayers[imageLayerID].MapImages[imageID].Texture, target, null, color, 0, Vector2.Zero, SpriteEffects.None, layerDepth);
        }
Example #2
0
        /// <summary>
        /// Draws the lines that make up the Polygon
        /// </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 polgon lines</param>
        /// <param name="layerDepth">LayerDepth value to pass to SpriteBatch</param>
        /// <param name="fillColor">The color value to fill the polygon</param>
        public void DrawFilled(SpriteBatch spriteBatch, Rectangle region, Texture2D texture, Single lineWidth, Color color, Color fillColor, Single layerDepth)
        {
            for (int i = 0; i < Lines.Length; i++)
            {
                Line.Draw(spriteBatch, Lines[i], region, texture, lineWidth, color, layerDepth);
            }

            spriteBatch.Draw(this.Texture, Map.Translate(this.Bounds, region), null, fillColor, 0, Vector2.Zero, 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(SpriteBatch spriteBatch, int objectLayerID, int objectID, ref Rectangle region, float layerDepth, ref Color color)
 {
     spriteBatch.Draw(
         this.Tilesets[this.SourceTiles[this.ObjectLayers[objectLayerID].MapObjects[objectID].TileID.Value].TilesetID].Texture,
         Map.Translate(this.ObjectLayers[objectLayerID].MapObjects[objectID].Bounds, region),
         this.SourceTiles[this.ObjectLayers[objectLayerID].MapObjects[objectID].TileID.Value].Source,
         color,
         0,
         this.SourceTiles[this.ObjectLayers[objectLayerID].MapObjects[objectID].TileID.Value].Origin,
         SpriteEffects.None,
         layerDepth);
 }
Example #4
0
 private void DrawTileObject(SpriteBatch spriteBatch, MapObject mapObject, ref Rectangle region, float layerDepth, ref Color color)
 {
     spriteBatch.Draw(
         this.Tilesets[this.SourceTiles[mapObject.TileID.Value].TilesetID].Texture,
         Map.Translate(mapObject.Bounds, region),
         this.SourceTiles[mapObject.TileID.Value].Source,
         color,
         0,
         this.SourceTiles[mapObject.TileID.Value].Origin,
         SpriteEffects.None,
         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(SpriteBatch spriteBatch, ref Rectangle rect, ref Rectangle region, Single layerDepth, ref Color linecolor, ref Color fillColor)
        {
            if (Map._whiteTexture == null)
            {
                throw new Exception("Map.InitObjectDrawing must be called before Map is loaded to enable object rendering");
            }

            Rectangle target = Map.Translate(rect, region);

            spriteBatch.Draw(Map._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, Map._whiteTexture, Map._lineThickness, linecolor, layerDepth);
            Line.Draw(spriteBatch, Line.FromPoints(new Vector2(rect.Left, rect.Top), new Vector2(rect.Left, rect.Bottom)), region, Map._whiteTexture, Map._lineThickness, linecolor, layerDepth);
            Line.Draw(spriteBatch, Line.FromPoints(new Vector2(rect.Left, rect.Bottom), new Vector2(rect.Right, rect.Bottom)), region, Map._whiteTexture, Map._lineThickness, linecolor, layerDepth);
            Line.Draw(spriteBatch, Line.FromPoints(new Vector2(rect.Right, rect.Bottom), new Vector2(rect.Right, rect.Top)), region, Map._whiteTexture, Map._lineThickness, linecolor, layerDepth);
        }
Example #6
0
        /// <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(SpriteBatch spriteBatch, Line line, Rectangle region, Texture2D texture, Single lineWidth, Color color, Single layerDepth)
        {
            Vector2 start = Map.Translate(line.Start, region);

            spriteBatch.Draw(texture, start, null, color, line.Angle, Vector2.Zero, new Vector2(line.Length, lineWidth), SpriteEffects.None, layerDepth);
        }