FuncWorks.XNA.XTiled.Map.Translate C# (CSharp) Method

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
        public static Point Translate(Point location, Rectangle relativeTo)
        {
            location.X = location.X - relativeTo.X;
            location.Y = location.Y - relativeTo.Y;
            return location;
        }

Same methods

Map::Translate ( Rectangle location, Rectangle relativeTo ) : Rectangle
Map::Translate ( Vector2 location, Rectangle relativeTo ) : Vector2
Map::Translate ( Point &location, Rectangle &relativeTo ) : void
Map::Translate ( Rectangle &location, Rectangle &relativeTo ) : void
Map::Translate ( Vector2 &location, Rectangle &relativeTo ) : void

Usage Example

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);
        }
All Usage Examples Of FuncWorks.XNA.XTiled.Map::Translate