2D Toolkit Forum

2D Toolkit => Support => Topic started by: robutmike on December 22, 2013, 06:40:52 pm

Title: How to get tile position relative to the tilemap grid, not world space
Post by: robutmike on December 22, 2013, 06:40:52 pm
I am having trouble finding a way to get a tile's position relative to the tilemap. For example, getTile returns the sprite ID. GetTilePosition returns the position in world space. I need to get a tile's x and y position in the tilemap.

SetTile sets the tile in the tilemap in this way, not in world space.  Surely there is a way to get this position as well.

Any help would be greatly appreciated.

Thank you very much,
Mike
Title: Re: How to get tile position relative to the tilemap grid, not world space
Post by: unikronsoftware on December 22, 2013, 10:57:55 pm
Get a tiles x & y position from what exactly?
If its from a world position, then GetTileAtPosition gives you x and y coordinates from a world pos.
Title: Re: How to get tile position relative to the tilemap grid, not world space
Post by: robutmike on December 23, 2013, 12:28:10 am
I am referring to it's position in the grid of the tilemap itself.

For example, the bottom left tile on a 100 wide, 100 tall tilemap, is 0,0 and the top right tile is 99,99.

Does that make sense?

Thanks!
Mike
Title: Re: How to get tile position relative to the tilemap grid, not world space
Post by: robutmike on December 23, 2013, 01:07:10 am
As a further example:

Let's say I want to build two tiles next one another, but I only build the first one, and write a loop to find the first tile and then build a second tile to the right of the first tile's location.

I can do this manually by saying:

tileMap.SetTile(0, 0, layer, tileID); // Build a tile in the bottom left of the tilemap, at the 0,0 location
tileMap.SetTile(1, 0, layer, tileID); //Build a tile to the right of the first tile

However, if I wanted to find the first tile and then get it's X and Y in the TILEMAP not in the worldspace, I cannot find a way to do that. I want to return 0,0 for the first tile, then say something like:

tileMap.SetTile(firstTile.x + 1, 0, layer, tileID);

Does that make more sense?

Thank you,
Mike

Title: Re: How to get tile position relative to the tilemap grid, not world space
Post by: robutmike on December 23, 2013, 04:48:00 am
I figured out another way to do what I needed to do.