I'm working with tiled and have a question about collision detection with the map. It's easy enough to check to see if my object is colliding with a tile on a blocked layer with something like:
var blockLayer = map.GetLayer<TiledMapTileLayer>("Block");
int tx = (int)(position.X / map.TileWidth);
int ty = (int)(position.Y / map.TileHeight);
if (blockLayer.TryGetTile(tx, ty, out tile))
var id = tile.Value.GlobalIdentifier;
But that leaves me without a few bits of crucial information that I need and I'm wondering if they're available in the tiled extension and I'm just not finding them?
The first is the X,Y coordinates of the tile I'm colliding with. If my object is falling at a rate of 10px per update cycle it's possible I've fallen several pixels into the tile when the collision is detected, and I'd like to reset the objects Y position to the top of the tile. (for example) If I go back in the GitHub repo, I see that the tile (X,Y) coordinates were available a few years ago when the extension was housed under Extended.Maps.Tiled, but seem to have disappeared with a major rewrite at some point... but I honestly don't fully understand the new implementation of Tile.cs, so I might just be missing if those values are available.
If not, any suggestions on the best way to find them? My best(?) ideas are to run some math using world size, tile size and index of tile, but I think I'm going to have problems making that work consistently, or to back my object up along the vector it's moving and re-run the collision check until it's false and setting the position there... which seems needlessly expensive.