title: Sorting of isometric SKTileMapNode incorrect?
body: <p>I'm programmatically using <code>SKTileMapNode</code>. The code is C# (Xamarin.iOS) but should be readable by every Swift/ObjC developer.</p>
  
  <p>The problem is that the sorting of tiles in isometric projection seems to be incorrect and I cannot see why. To test, the map has 1 row and 5 columns.</p>
  
  <p>See the screenshot:</p>
  
  <p><a href="https://i.stack.imgur.com/SVhjD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SVhjD.png" alt="Sorting"></a></p>
  
  <p>The tiles at 0|0 and 2|0 are in front of the others. The pyramid styled tile at 4|0 however, is drawn correctly in front of the one at 3|0.</p>
  
  <p>I'm using two simple tiles:</p>
  
  <p><a href="https://i.stack.imgur.com/wzCZV.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wzCZV.png" alt="Tile1"></a>
  <a href="https://i.stack.imgur.com/bcIvP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bcIvP.png" alt="Tile2"></a></p>
  
  <p>The first one has a resolution of 133x83px and the second one is 132x131px</p>
  
  <p>This is what it looks like in Tiled and what I am trying to reproduce:</p>
  
  <p><a href="https://i.stack.imgur.com/66G6p.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/66G6p.png" alt="Tiled"></a></p>
  
  <p>The tile map is setup and added to the scene using the following code:</p>
  
  <pre><code>var tileDef1 = new SKTileDefinition (SKTexture.FromImageNamed ("landscapeTiles_014"));
  var tileDef2 = new SKTileDefinition (SKTexture.FromImageNamed ("landscapeTiles_036"));
  
  var tileGroup1 = new SKTileGroup (tileDef1);
  var tileGroup2 = new SKTileGroup (tileDef2);
  
  var tileSet = new SKTileSet (new [] { tileGroup1, tileGroup2 }, SKTileSetType.Isometric);
  
  var tileMap =  SKTileMapNode.Create(tileSet, 5, 2, new CGSize (128, 64));
  
  tileMap.Position = new CGPoint (0, 0);
  
  tileMap.SetTileGroup (tileGroup1, 0, 0);
  tileMap.SetTileGroup (tileGroup2, 1, 0);
  tileMap.SetTileGroup (tileGroup1, 2, 0);
  tileMap.SetTileGroup (tileGroup2, 3, 0);
  tileMap.SetTileGroup (tileGroup2, 4, 0);
  
  tileMap.AnchorPoint = new CGPoint (0, 0);
  Add (tileMap);
  </code></pre>
  
  <p>If first suspected an incorrect tile size. The tile size used to initialise the tile map (128|64) is the size of the diamond shaped base of the tile. If using a flat tile, this is identical to the texture size. For tiles with a height, it differs. However, changing the tile size affects the alignment of the tiles an the size I'm using is the same as in Tiled and it's giving the correct result, so that cannot be the culprit.</p>
  
  <p>What am I doing wrong or where am I thinking wrong?</p>