diff --git a/MLEM.Extended/Tiled/IndividualTiledMapRenderer.cs b/MLEM.Extended/Tiled/IndividualTiledMapRenderer.cs index 6a33c3b..f143a0b 100644 --- a/MLEM.Extended/Tiled/IndividualTiledMapRenderer.cs +++ b/MLEM.Extended/Tiled/IndividualTiledMapRenderer.cs @@ -53,7 +53,7 @@ namespace MLEM.Extended.Tiled { var tilesetTile = tileset.GetTilesetTile(tile, this.map); var pos = new Point(x, y); var depth = this.depthFunction(tile, layer, layerIndex, pos); - this.drawInfos[layerIndex, x, y] = new TileDrawInfo(this, tileset, tilesetTile, pos, depth); + this.drawInfos[layerIndex, x, y] = new TileDrawInfo(this, tile, tileset, tilesetTile, pos, depth); } public void Draw(SpriteBatch batch, RectangleF? frustum = null) { @@ -88,24 +88,30 @@ namespace MLEM.Extended.Tiled { private readonly IndividualTiledMapRenderer renderer; private readonly TiledMapTileset tileset; - private readonly TiledMapTilesetTile tile; + private readonly TiledMapTilesetTile tilesetTile; private readonly Point position; private readonly float depth; + private readonly SpriteEffects flipping; - public TileDrawInfo(IndividualTiledMapRenderer renderer, TiledMapTileset tileset, TiledMapTilesetTile tile, Point position, float depth) { + public TileDrawInfo(IndividualTiledMapRenderer renderer, TiledMapTile tile, TiledMapTileset tileset, TiledMapTilesetTile tilesetTile, Point position, float depth) { this.renderer = renderer; this.tileset = tileset; - this.tile = tile; + this.tilesetTile = tilesetTile; this.position = position; this.depth = depth; + + if (tile.IsFlippedHorizontally) + this.flipping |= SpriteEffects.FlipHorizontally; + if (tile.IsFlippedVertically) + this.flipping |= SpriteEffects.FlipVertically; } public void Draw(SpriteBatch batch) { - var id = this.tile.LocalTileIdentifier; - if (this.tile is TiledMapTilesetAnimatedTile animated) + var id = this.tilesetTile.LocalTileIdentifier; + if (this.tilesetTile is TiledMapTilesetAnimatedTile animated) id = animated.CurrentAnimationFrame.LocalTileIdentifier; var drawPos = new Vector2(this.position.X * this.renderer.map.TileWidth, this.position.Y * this.renderer.map.TileHeight); - batch.Draw(this.tileset.Texture, drawPos, this.tileset.GetTileRegion(id), Color.White, 0, Vector2.Zero, 1, SpriteEffects.None, this.depth); + batch.Draw(this.tileset.Texture, drawPos, this.tileset.GetTileRegion(id), Color.White, 0, Vector2.Zero, 1, this.flipping, this.depth); } } diff --git a/Sandbox/Content/Tiled/Map.tmx b/Sandbox/Content/Tiled/Map.tmx index 684e5dd..b0e1771 100644 --- a/Sandbox/Content/Tiled/Map.tmx +++ b/Sandbox/Content/Tiled/Map.tmx @@ -1,5 +1,5 @@ - + @@ -250,9 +250,9 @@ 0,336,292,293,326,325,326,326,326,328,326,296,297,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,356,325,326,357,358,358,358,360,326,328,361,0,0,0,0,0,0,269,270,0,0,0,0,0,0,0,0,271,0,0,0,0,0,0,0,0,0,0,269,270,0,0,0,0,0,0,0,0, 0,0,356,357,358,389,0,0,0,392,358,360,361,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,388,389,0,0,0,0,0,0,0,392,393,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,336,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,269,270,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,173,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,388,389,0,0,0,0,0,0,0,392,393,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,43,43,43,43,43,43,43,0,0,0,0,0,0,0,0,336,0,0,0,0, +0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,43,8,2147483656,9,1073741833,3221225545,43,0,0,0,0,0,0,0,0,0,0,0,0,0, +0,0,269,270,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,173,0,0,0,0,0,0,43,43,43,43,43,43,43,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,205,13,14,14,14,14,14,14,14,14,14,14,14,14,14,15,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,271,0,0,0,0,0,0,269,270,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,333,334,335,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, diff --git a/Sandbox/Content/Tiled/Tiles.png b/Sandbox/Content/Tiled/Tiles.png index 16894a8..bc1175d 100644 Binary files a/Sandbox/Content/Tiled/Tiles.png and b/Sandbox/Content/Tiled/Tiles.png differ