GMS 2 [SOLVED] How does Gm:S2 assign tile IDs?

SOLVED: For anyone wondering about the title question as well, tile IDs are assigned left to right, top to bottom, starting with value 0 in the upper-left corner.

Title. I'm working on a tile-based collision system, and while I have all the movement and stopping code down, I need the part that identifies tiles to collide with. I've heard of systems that use a separate collision layer to do this, using one tile that's registered as a wall with ID 1 and then testing the appropriate commands for 0 or 1, but I wish to do both my aesthetic tiles and my collisions all with one tile layer. To do this, my game will have a list of every tile on the tileset that should be registered as a wall, and then test for any tiles on that list to perform collisions with, as per any other collision system.

To make this list, however, I need to know one crucial bit of information about how Gamemaker handles its tiles: How does it assign tile IDs? What's the pattern to it? Does it just assign them in order, left to right and top to bottom, or is there another pattern to it? I've checked the documentation, but found nothing on what order the game assigns tile IDs in. Of course, I might just be blind...

Thanks for the assistance!
~Pir
 
Last edited:

immortalx

Member
The tile indices are indeed assigned as you imagined (left to right and top to bottom), but the very first tile (zero position) is reserved. That means that your tileset should start at position 1.
Keep in mind that GMS2 has a feature which allows you to store additional information about rotation, mirroring and flipping in each tile, in what is called the tile data blob. There are functions that allow you to retrieve/set this information.
If you don't use that feature, then it's straightforward. For example, the function tilemap_get_at_pixel will return the index of the tile within the tilemap, at the specified x,y position within the room.
 

TheouAegis

Member
Supposedly you can also assign other data too if your tile sheets are small enough. The mirror/flip/rotation bits are high enough up that any bits between them and the last bit of your tileset can be set and used to denote any kind of info you want.
 
The tile indices are indeed assigned as you imagined (left to right and top to bottom), but the very first tile (zero position) is reserved. That means that your tileset should start at position 1.
Keep in mind that GMS2 has a feature which allows you to store additional information about rotation, mirroring and flipping in each tile, in what is called the tile data blob. There are functions that allow you to retrieve/set this information.
If you don't use that feature, then it's straightforward. For example, the function tilemap_get_at_pixel will return the index of the tile within the tilemap, at the specified x,y position within the room.
Thank you for the assistance!
 
Top