/// <summary> /// Render the Entity. /// </summary> /// <param name="offsetX">Offset x.</param> /// <param name="offsetY">Offset y.</param> /// <param name="tileOffsetX">Tile offset x.</param> /// <param name="tileOffsetY">Tile offset y.</param> /// <param name="TileWidth">Tile width.</param> /// <param name="TileHeight">Tile height.</param> public void Render(float offsetX, float offsetY, float tileOffsetX, float tileOffsetY) { if (sprite == null || CurrentMap == null) { return; } bool shouldFlipX = sprite.ShouldFlipX; RectangleF rect = GetTileRectangle(offsetX, offsetY, tileOffsetX, tileOffsetY); rect.Width = sprite.MaxWidth; rect.Height = sprite.MaxHeight; RectangleF tileRectangle = new RectangleF(0, 0, TileSizeX * CurrentMap.TileWidth, TileSizeY * CurrentMap.TileHeight); rect.X -= (rect.Width * 0.5f - tileRectangle.Width * 0.5f); rect.Y -= (rect.Height * 0.5f - tileRectangle.Height * 0.5f); if (sprite.CurrentFrame != null) { sprite.CurrentFrame.texture.RenderOnScreen(rect, shouldFlipX, false); } if (DebugOptions.ShowUnitFrames) { WWTexture.RenderRectangle(rect, Color.Blue); } }
/// <summary> /// Returns a rectangle encompassing (in screen coordinates) the bounding box of the entity /// </summary> internal RectangleF GetTileRectangle(float offsetX, float offsetY, float tileOffsetX, float tileOffsetY) { int startTileX = ((int)tileOffsetX / CurrentMap.TileWidth); int startTileY = ((int)tileOffsetY / CurrentMap.TileHeight); RectangleF rect = new RectangleF(); rect.X = offsetX + (X - startTileX) * CurrentMap.TileWidth; // - (TileWidth / 2); rect.Y = offsetY + (Y - startTileY) * CurrentMap.TileHeight; // - (TileHeight / 2); rect.Width = TileSizeX * CurrentMap.TileWidth; rect.Height = TileSizeY * CurrentMap.TileHeight; return(rect); }