diff --git a/Source/MonoGame.Extended.Content.Pipeline.Tests/TestData/isometric.tmx b/Source/MonoGame.Extended.Content.Pipeline.Tests/TestData/isometric.tmx
new file mode 100644
index 00000000..3f3168c7
--- /dev/null
+++ b/Source/MonoGame.Extended.Content.Pipeline.Tests/TestData/isometric.tmx
@@ -0,0 +1,76 @@
+
+
+
diff --git a/Source/MonoGame.Extended.Content.Pipeline.Tests/TestData/isometric_tileset.png b/Source/MonoGame.Extended.Content.Pipeline.Tests/TestData/isometric_tileset.png
new file mode 100644
index 00000000..4c6f1b4f
Binary files /dev/null and b/Source/MonoGame.Extended.Content.Pipeline.Tests/TestData/isometric_tileset.png differ
diff --git a/Source/MonoGame.Extended.Content.Pipeline.Tests/TiledMapImporterProcessorTests.cs b/Source/MonoGame.Extended.Content.Pipeline.Tests/TiledMapImporterProcessorTests.cs
index e2146451..92d15ad2 100644
--- a/Source/MonoGame.Extended.Content.Pipeline.Tests/TiledMapImporterProcessorTests.cs
+++ b/Source/MonoGame.Extended.Content.Pipeline.Tests/TiledMapImporterProcessorTests.cs
@@ -1,6 +1,7 @@
using System.Linq;
using Microsoft.Xna.Framework.Content.Pipeline;
using MonoGame.Extended.Content.Pipeline.Tiled;
+using MonoGame.Extended.Maps.Tiled;
using NSubstitute;
using NUnit.Framework;
@@ -28,6 +29,7 @@ namespace MonoGame.Extended.Content.Pipeline.Tests
Assert.AreEqual("42", map.Properties[0].Value);
Assert.AreEqual(1, map.Tilesets.Count);
Assert.AreEqual(3, map.Layers.Count);
+ Assert.AreEqual(TmxOrientation.Orthogonal,map.Orientation);
var tileset = map.Tilesets.First();
Assert.AreEqual(1, tileset.FirstGid);
@@ -71,7 +73,8 @@ namespace MonoGame.Extended.Content.Pipeline.Tests
Assert.AreEqual("1", tileLayer1.Properties[0].Value);
Assert.AreEqual("customlayerprop2", tileLayer1.Properties[1].Name);
- Assert.AreEqual("2", tileLayer1.Properties[1].Value);}
+ Assert.AreEqual("2", tileLayer1.Properties[1].Value);
+ }
[Test]
public void TiledMapImporter_Xml_Test()
diff --git a/Source/MonoGame.Extended.Content.Pipeline/Tiled/TiledMapWriter.cs b/Source/MonoGame.Extended.Content.Pipeline/Tiled/TiledMapWriter.cs
index de68f3fa..6cd0fa90 100644
--- a/Source/MonoGame.Extended.Content.Pipeline/Tiled/TiledMapWriter.cs
+++ b/Source/MonoGame.Extended.Content.Pipeline/Tiled/TiledMapWriter.cs
@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System;
+using System.Collections.Generic;
using System.Globalization;
using System.IO;
using Microsoft.Xna.Framework;
@@ -20,6 +21,7 @@ namespace MonoGame.Extended.Content.Pipeline.Tiled
writer.Write(map.Height);
writer.Write(map.TileWidth);
writer.Write(map.TileHeight);
+ writer.Write(Convert.ToInt32(map.Orientation));
WriteCustomProperties(writer, map.Properties);
writer.Write(map.Tilesets.Count);
diff --git a/Source/MonoGame.Extended/Maps/Tiled/TiledMap.cs b/Source/MonoGame.Extended/Maps/Tiled/TiledMap.cs
index bae3f11b..78a62672 100644
--- a/Source/MonoGame.Extended/Maps/Tiled/TiledMap.cs
+++ b/Source/MonoGame.Extended/Maps/Tiled/TiledMap.cs
@@ -9,7 +9,12 @@ namespace MonoGame.Extended.Maps.Tiled
{
public class TiledMap
{
- public TiledMap(GraphicsDevice graphicsDevice, int width, int height, int tileWidth, int tileHeight)
+ public TiledMap(GraphicsDevice graphicsDevice,
+ int width,
+ int height,
+ int tileWidth,
+ int tileHeight,
+ TiledMapOrientation orientation = TiledMapOrientation.Orthogonal)
{
Width = width;
Height = height;
@@ -20,19 +25,21 @@ namespace MonoGame.Extended.Maps.Tiled
_graphicsDevice = graphicsDevice;
_layers = new List();
_tilesets = new List();
+ Orientation = orientation;
}
private readonly List _tilesets;
private readonly GraphicsDevice _graphicsDevice;
private readonly List _layers;
- public int Width { get; private set; }
- public int Height { get; private set; }
- public int TileWidth { get; private set; }
- public int TileHeight { get; private set; }
+ public int Width { get; }
+ public int Height { get; }
+ public int TileWidth { get; }
+ public int TileHeight { get; }
public Color? BackgroundColor { get; set; }
public TiledRenderOrder RenderOrder { get; set; }
public TiledProperties Properties { get; private set; }
+ public TiledMapOrientation Orientation { get; }
public IEnumerable Layers
{
diff --git a/Source/MonoGame.Extended/Maps/Tiled/TiledMapOrientation.cs b/Source/MonoGame.Extended/Maps/Tiled/TiledMapOrientation.cs
new file mode 100644
index 00000000..b877c4c5
--- /dev/null
+++ b/Source/MonoGame.Extended/Maps/Tiled/TiledMapOrientation.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace MonoGame.Extended.Maps.Tiled
+{
+ public enum TiledMapOrientation
+ {
+ Orthogonal = 1,
+ Isometric = 2,
+ Staggered = 3
+ }
+}
diff --git a/Source/MonoGame.Extended/Maps/Tiled/TiledMapReader.cs b/Source/MonoGame.Extended/Maps/Tiled/TiledMapReader.cs
index ce9c2641..8b3e3933 100644
--- a/Source/MonoGame.Extended/Maps/Tiled/TiledMapReader.cs
+++ b/Source/MonoGame.Extended/Maps/Tiled/TiledMapReader.cs
@@ -16,7 +16,8 @@ namespace MonoGame.Extended.Maps.Tiled
width: reader.ReadInt32(),
height: reader.ReadInt32(),
tileWidth: reader.ReadInt32(),
- tileHeight: reader.ReadInt32())
+ tileHeight: reader.ReadInt32(),
+ orientation: (TiledMapOrientation)reader.ReadInt32())
{
BackgroundColor = backgroundColor,
RenderOrder = renderOrder
diff --git a/Source/MonoGame.Extended/Maps/Tiled/TiledTileLayer.cs b/Source/MonoGame.Extended/Maps/Tiled/TiledTileLayer.cs
index 32a5e85a..43412a2c 100644
--- a/Source/MonoGame.Extended/Maps/Tiled/TiledTileLayer.cs
+++ b/Source/MonoGame.Extended/Maps/Tiled/TiledTileLayer.cs
@@ -54,22 +54,59 @@ namespace MonoGame.Extended.Maps.Tiled
{
var region = _map.GetTileRegion(tile.Id);
- if (region != null)
- {
- // not exactly sure why we need to compensate 1 pixel here. Could be a bug in MonoGame?
- var tx = tile.X * (_map.TileWidth - 1);
- var ty = tile.Y * (_map.TileHeight - 1);
-
- _spriteBatch.Draw(region, new Rectangle(tx, ty, region.Width, region.Height), Color.White);
- }
+ if(region == null) continue;
+
+ RenderLayer(_map, tile, region);
}
_spriteBatch.End();
}
-
+
+ private void RenderLayer(TiledMap map, TiledTile tile, TextureRegion2D region)
+ {
+ switch (map.Orientation)
+ {
+ case TiledMapOrientation.Orthogonal:
+ RenderOrthogonal(tile,region);
+ break;
+ case TiledMapOrientation.Isometric:
+ RenderIsometric(tile, region);
+ break;
+ case TiledMapOrientation.Staggered:
+ throw new NotImplementedException("Staggered maps are currently not supported");
+ break;
+ default:
+ throw new ArgumentOutOfRangeException();
+ }
+ }
+
+ private void RenderOrthogonal(TiledTile tile, TextureRegion2D region)
+ {
+ // not exactly sure why we need to compensate 1 pixel here. Could be a bug in MonoGame?
+ var tx = tile.X*(_map.TileWidth - 1);
+ var ty = tile.Y*(_map.TileHeight - 1);
+
+ _spriteBatch.Draw(region, new Rectangle(tx, ty, region.Width, region.Height), Color.White);
+ }
+
+ private void RenderIsometric(TiledTile tile, TextureRegion2D region)
+ {
+ var tx = (tile.X*(_map.TileWidth / 2)) - (tile.Y*(_map.TileWidth / 2))
+ //Center
+ + (_map.Width * (_map.TileWidth/2))
+ //Compensate Bug?
+ - (_map.TileWidth / 2);
+
+ var ty = (tile.Y*(_map.TileHeight/2)) + (tile.X*(_map.TileHeight/2))
+ //Compensate Bug?
+ - (_map.TileWidth + _map.TileHeight);
+
+ _spriteBatch.Draw(region, new Rectangle(tx, ty, region.Width, region.Height), Color.White);
+ }
+
public TiledTile GetTile(int x, int y)
{
- return _tiles[x + y * Width];
+ return _tiles[x + y*Width];
}
private Func> GetRenderOrderFunction()
@@ -115,7 +152,7 @@ namespace MonoGame.Extended.Maps.Tiled
yield return GetTile(x, y);
}
}
-
+
private IEnumerable GetTilesLeftUp()
{
for (var y = Height - 1; y >= 0; y--)
diff --git a/Source/MonoGame.Extended/MonoGame.Extended.csproj b/Source/MonoGame.Extended/MonoGame.Extended.csproj
index 95fcbb28..d8724924 100644
--- a/Source/MonoGame.Extended/MonoGame.Extended.csproj
+++ b/Source/MonoGame.Extended/MonoGame.Extended.csproj
@@ -55,6 +55,7 @@
+
diff --git a/Source/Sandbox/Content/Content.mgcb b/Source/Sandbox/Content/Content.mgcb
index fdfb056d..feb35e0c 100644
--- a/Source/Sandbox/Content/Content.mgcb
+++ b/Source/Sandbox/Content/Content.mgcb
@@ -6,6 +6,7 @@
/platform:Windows
/config:
/profile:Reach
+/compress:False
#-------------------------------- References --------------------------------#
@@ -21,7 +22,6 @@
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
-/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:hills.png
@@ -36,7 +36,6 @@
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
-/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:tmw_desert_spacing.png
@@ -48,7 +47,6 @@
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
-/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:free-tileset.png
@@ -65,7 +63,6 @@
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
-/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:test-tileset.png
@@ -82,7 +79,6 @@
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
-/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:stump.png
@@ -119,7 +115,6 @@
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
-/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:fireball.png
@@ -136,7 +131,6 @@
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
-/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:zombie.png
@@ -153,7 +147,22 @@
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
-/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Fonts/courier-new-32_0.png
+#begin isometric.tmx
+/importer:TiledMapImporter
+/processor:TiledMapProcessor
+/build:isometric.tmx
+
+#begin isometric_tileset.png
+/importer:TextureImporter
+/processor:TextureProcessor
+/processorParam:ColorKeyColor=255,0,255,255
+/processorParam:ColorKeyEnabled=True
+/processorParam:GenerateMipmaps=False
+/processorParam:PremultiplyAlpha=True
+/processorParam:ResizeToPowerOfTwo=False
+/processorParam:TextureFormat=Color
+/build:isometric_tileset.png
+
diff --git a/Source/Sandbox/Content/isometric.tmx b/Source/Sandbox/Content/isometric.tmx
new file mode 100644
index 00000000..452b2440
--- /dev/null
+++ b/Source/Sandbox/Content/isometric.tmx
@@ -0,0 +1,58 @@
+
+
diff --git a/Source/Sandbox/Content/isometric_tileset.png b/Source/Sandbox/Content/isometric_tileset.png
new file mode 100644
index 00000000..4c6f1b4f
Binary files /dev/null and b/Source/Sandbox/Content/isometric_tileset.png differ