Files
MonoGame.Extended/Source/MonoGame.Extended.Tiled/TiledMapHelper..cs
T
Lucas Girouard-StranksandDylan Wilson b22a062147 Fix Tiled Problems (#332)
* Add Tiled Content Pipeline library to NuGet

* Update Tiled NuGet package elements.

* Remove dependency on Graphics

* Update csproj for removal of Graphics dependency

* Fix build errors

* Fix problems
2017-01-20 21:08:14 +10:00

43 lines
1.7 KiB
C#

#region
using Microsoft.Xna.Framework;
#endregion
namespace MonoGame.Extended.Tiled
{
internal static class TiledMapHelper
{
internal static Rectangle GetTileSourceRectangle(int localTileIdentifier, int tileWidth, int tileHeight,
int columns, int margin, int spacing)
{
var x = margin + localTileIdentifier % columns * (tileWidth + spacing);
var y = margin + localTileIdentifier / columns * (tileHeight + spacing);
return new Rectangle(x, y, tileWidth, tileHeight);
}
internal static Point2 GetOrthogonalPosition(int tileX, int tileY, int tileWidth, int tileHeight)
{
var x = tileX * tileWidth;
var y = tileY * tileHeight;
return new Vector2(x, y);
}
internal static Point2 GetIsometricPosition(int tileX, int tileY, int tileWidth, int tileHeight)
{
// You can think of an isometric Tiled map as a regular orthogonal map that is rotated -45 degrees
// i.e.: the origin (0, 0) is the top tile of the diamond grid;
// (mapWidth, 0) is the far right tile of the diamond grid
// (0, mapHeight) is the far left tile of the diamond grid
// (mapWidth, mapHeight) is the bottom tile of the diamond grid
var halfTileWidth = tileWidth * 0.5f;
var halfTileHeight = tileHeight * 0.5f;
// -1 because we want the top the tile-diamond (top-center) to be the origin in tile space
var x = (tileX - tileY - 1) * halfTileWidth;
var y = (tileX + tileY) * halfTileHeight;
return new Vector2(x, y);
}
}
}