• Hey! Guest! The 39th GMC Jam will take place between November 26th, 12:00 UTC and November 30th, 12:00 UTC. Why not join in! Click here to find out more!

GMS 2 Find Tile Layer's Width and Height

Is there any way to find the width, and height of a tile layer. Width meaning the x of the first tile in the left direction to the x of the last tile + the tile's width in the right direction. Height meaning the y of the first tile in the up direction to the y of the last tile + the tile's height in the down direction. Finding how many tiles are in each direction in the tile layer would also help me get the result. I'm assuming I don't already know how wide or high the given tile layer is. I'm talking about an in game tile layer (an arrangement of tiles), not the tile set resources, if that was ambiguous.

Edit:
So I tried tilemap_get_width(i), but this just gives me how many could fit in the room horizontally, not the amount of tiles from the first horizontally placed to the last horizontally placed. It count's the empties before and after.
 
Last edited:

Slyddar

Member
The tile layer dimensions will always fill the room, as best as it can. To get how far the tile layer is populated for the width and height, I would imagine you would have to calculate that yourself, using a loop and some tilemap_get_at_pixel testing. You could start at the extremity of the room and test every tile row/column counting down.
 
Last edited:
The tile layer dimensions will always fill the room, as best as it. To get how far the tile layer is populated for the width and height, I would imagine you would have to calculate that yourself, using a loop and some tilemap_get_at_pixel testing. You could start at the extremity of the room and test every tile row/column counting down.
Would have thought getting the dimensions of a tilemap would have been built in. The loop method sounds expensive, but I guess I'll give it a try. Not sure why we have tilemap_get_width(i) if not for that. Dividing room height by tile cell size is easier to do yourself than this is going to be.
 

samspade

Member
tilemap width and height are the size of the grid, which are not necessarily connected to the size of the room. So if you want to know the tile map's width and height in pixels it's just the tile map's width times the width of a tile and the tile map's height times the height of a tile. There might be a way to find this through code that I'm not aware of, but I think you might just have to remember what you set it to in the IDE since it can be set to anything and isn't inherently tied to a sprite. See: https://docs2.yoyogames.com/source/_build/2_interface/1_editors/tilesets.html.
 
Top