1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-06-05 06:33:38 +02:00

added tile flipping to the renderer

This commit is contained in:
Ellpeck 2020-01-01 12:18:35 +01:00
parent 43b665642d
commit 45c725f5ef
3 changed files with 17 additions and 11 deletions

View file

@ -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);
}
}

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.2" tiledversion="1.2.4" orientation="orthogonal" renderorder="right-down" width="50" height="50" tilewidth="16" tileheight="16" infinite="0" nextlayerid="7" nextobjectid="32">
<map version="1.2" tiledversion="1.3.1" orientation="orthogonal" renderorder="right-down" compressionlevel="0" width="50" height="50" tilewidth="16" tileheight="16" infinite="0" nextlayerid="7" nextobjectid="32">
<tileset firstgid="1" source="Tileset.tsx"/>
<layer id="1" name="Ground" width="50" height="50">
<data encoding="csv">
@ -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,

Binary file not shown.

Before

Width:  |  Height:  |  Size: 53 KiB

After

Width:  |  Height:  |  Size: 46 KiB