almost finished render order for tiled maps

This commit is contained in:
Dylan Wilson
2015-08-07 17:43:23 +10:00
parent d491332dd0
commit 2d478b5313
12 changed files with 136 additions and 6 deletions
@@ -3,6 +3,7 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content.Pipeline;
using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
using MonoGame.Extended.Tiled;
using TiledSharp;
namespace MonoGame.Extended.Content.Pipeline.Tiled
{
@@ -13,6 +14,7 @@ namespace MonoGame.Extended.Content.Pipeline.Tiled
{
var map = value.Map;
output.Write(new Color(map.BackgroundColor.R, map.BackgroundColor.G, map.BackgroundColor.B));
output.Write(ConvertRenderOrder(map.RenderOrder).ToString());
output.Write(map.Width);
output.Write(map.Height);
output.Write(map.TileWidth);
@@ -55,5 +57,22 @@ namespace MonoGame.Extended.Content.Pipeline.Tiled
{
return typeof (TiledMapReader).AssemblyQualifiedName;
}
private static TiledMapRenderOrder ConvertRenderOrder(TmxMap.RenderOrderType renderOrder)
{
switch (renderOrder)
{
case TmxMap.RenderOrderType.RightDown:
return TiledMapRenderOrder.RightDown;
case TmxMap.RenderOrderType.RightUp:
return TiledMapRenderOrder.RightUp;
case TmxMap.RenderOrderType.LeftDown:
return TiledMapRenderOrder.LeftDown;
case TmxMap.RenderOrderType.LeftUp:
return TiledMapRenderOrder.LeftUp;
default:
return TiledMapRenderOrder.RightDown;
}
}
}
}
@@ -53,6 +53,7 @@
<Compile Include="Tiled\TiledLayer.cs" />
<Compile Include="Tiled\TiledMap.cs" />
<Compile Include="Tiled\TiledMapReader.cs" />
<Compile Include="Tiled\TiledMapRenderOrder.cs" />
<Compile Include="Tiled\TiledTileSet.cs" />
<Compile Include="Graphics\ViewportAdapters\BoxingViewportAdapter.cs" />
<Compile Include="Graphics\ViewportAdapters\DefaultViewportAdapter.cs" />
+2 -2
View File
@@ -40,8 +40,8 @@ namespace MonoGame.Extended.Tiled
if (region != null)
{
// not exactly sure why we need to compensate 1 pixel here. Could be a bug in MonoGame?
var tx = x * (region.Width - 1);
var ty = y * (region.Height - 1);
var tx = x * (_tiledMap.TileWidth - 1);
var ty = y * (_tiledMap.TileHeight - 1);
_spriteBatch.Draw(region, new Rectangle(tx, ty, region.Width, region.Height), Color.White);
}
@@ -30,6 +30,7 @@ namespace MonoGame.Extended.Tiled
public int TileWidth { get; private set; }
public int TileHeight { get; private set; }
public Color? BackgroundColor { get; set; }
public TiledMapRenderOrder RenderOrder { get; set; }
public int WidthInPixels
{
@@ -1,3 +1,4 @@
using System;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using MonoGame.Extended.Content;
@@ -9,6 +10,7 @@ namespace MonoGame.Extended.Tiled
protected override TiledMap Read(ContentReader input, TiledMap existingInstance)
{
var backgroundColor = input.ReadColor();
var renderOrder = (TiledMapRenderOrder) Enum.Parse(typeof (TiledMapRenderOrder), input.ReadString(), true);
var tileMap = new TiledMap(
graphicsDevice: input.ContentManager.GetGraphicsDevice(),
width: input.ReadInt32(),
@@ -16,7 +18,8 @@ namespace MonoGame.Extended.Tiled
tileWidth: input.ReadInt32(),
tileHeight: input.ReadInt32())
{
BackgroundColor = backgroundColor
BackgroundColor = backgroundColor,
RenderOrder = renderOrder
};
var tileSetCount = input.ReadInt32();
@@ -0,0 +1,10 @@
namespace MonoGame.Extended.Tiled
{
public enum TiledMapRenderOrder
{
RightDown,
RightUp,
LeftDown,
LeftUp
}
}
+20
View File
@@ -87,3 +87,23 @@
/processor:TiledMapProcessor
/build:test-tileset-map1.tmx
#begin test-tileset-left-down.tmx
/importer:TiledMapImporter
/processor:TiledMapProcessor
/build:test-tileset-left-down.tmx
#begin test-tileset-left-up.tmx
/importer:TiledMapImporter
/processor:TiledMapProcessor
/build:test-tileset-left-up.tmx
#begin test-tileset-right-down.tmx
/importer:TiledMapImporter
/processor:TiledMapProcessor
/build:test-tileset-right-down.tmx
#begin test-tileset-right-up.tmx
/importer:TiledMapImporter
/processor:TiledMapProcessor
/build:test-tileset-right-up.tmx
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" renderorder="left-down" width="3" height="3" tilewidth="25" tileheight="25" backgroundcolor="#a6527c" nextobjectid="1">
<tileset firstgid="1" name="test-tileset" tilewidth="32" tileheight="32" spacing="2" margin="2">
<image source="../../../../../Temp/test-tileset/test-tileset.png" width="104" height="104"/>
</tileset>
<layer name="Tile Layer 1" width="3" height="3">
<data>
<tile gid="1"/>
<tile gid="2"/>
<tile gid="3"/>
<tile gid="4"/>
<tile gid="5"/>
<tile gid="6"/>
<tile gid="7"/>
<tile gid="8"/>
<tile gid="9"/>
</data>
</layer>
</map>
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" renderorder="left-up" width="3" height="3" tilewidth="25" tileheight="25" backgroundcolor="#a6527c" nextobjectid="1">
<tileset firstgid="1" name="test-tileset" tilewidth="32" tileheight="32" spacing="2" margin="2">
<image source="../../../../../Temp/test-tileset/test-tileset.png" width="104" height="104"/>
</tileset>
<layer name="Tile Layer 1" width="3" height="3">
<data>
<tile gid="1"/>
<tile gid="2"/>
<tile gid="3"/>
<tile gid="4"/>
<tile gid="5"/>
<tile gid="6"/>
<tile gid="7"/>
<tile gid="8"/>
<tile gid="9"/>
</data>
</layer>
</map>
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" renderorder="right-down" width="3" height="3" tilewidth="25" tileheight="25" backgroundcolor="#a6527c" nextobjectid="1">
<tileset firstgid="1" name="test-tileset" tilewidth="32" tileheight="32" spacing="2" margin="2">
<image source="../../../../../Temp/test-tileset/test-tileset.png" width="104" height="104"/>
</tileset>
<layer name="Tile Layer 1" width="3" height="3">
<data>
<tile gid="1"/>
<tile gid="2"/>
<tile gid="3"/>
<tile gid="4"/>
<tile gid="5"/>
<tile gid="6"/>
<tile gid="7"/>
<tile gid="8"/>
<tile gid="9"/>
</data>
</layer>
</map>
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.0" orientation="orthogonal" renderorder="right-up" width="3" height="3" tilewidth="25" tileheight="25" backgroundcolor="#a6527c" nextobjectid="1">
<tileset firstgid="1" name="test-tileset" tilewidth="32" tileheight="32" spacing="2" margin="2">
<image source="../../../../../Temp/test-tileset/test-tileset.png" width="104" height="104"/>
</tileset>
<layer name="Tile Layer 1" width="3" height="3">
<data>
<tile gid="1"/>
<tile gid="2"/>
<tile gid="3"/>
<tile gid="4"/>
<tile gid="5"/>
<tile gid="6"/>
<tile gid="7"/>
<tile gid="8"/>
<tile gid="9"/>
</data>
</layer>
</map>
+3 -3
View File
@@ -43,8 +43,8 @@ namespace Sandbox
_viewportAdapter = new BoxingViewportAdapter(GraphicsDevice, 800, 480);
_camera = new Camera2D(_viewportAdapter)
{
Zoom = 0.5f,
Position = new Vector2(900, 650)
Zoom = 1.5f,
//Position = new Vector2(900, 650)
};
Window.AllowUserResizing = true;
@@ -58,7 +58,7 @@ namespace Sandbox
_spriteBatch = new SpriteBatch(GraphicsDevice);
_backgroundTexture = Content.Load<Texture2D>("hills");
_bitmapFont = Content.Load<BitmapFont>("courier-new-32");
_tiledMap = Content.Load<TiledMap>("level01");
_tiledMap = Content.Load<TiledMap>("test-tileset-left-down");
}
protected override void UnloadContent()