SOLVED Get tileset tile width and height.

Sam04

Member
Is there a way to get the tile width and tile height of a tileset. I checked the manual and, apparently, the only functions related to tilesets are to get their texture information.

I need them because I want to create tilemaps, but one of the required data to create one is how many cells it will use. I want them to cover the entire room, so the obvious answer will be something like:
new_tilemap = layer_tilemap_create(target_layer, 0,0, tileset, room_width div tile_width, room_height div tile_height);

But, for that I need the information I am lacking. The good thing about tilesets is that they always have the same tile width and height no matter what; but if I am dynamically creating tilemaps through code using tilesets with different tile width and height I need a way to check this info through code so it always uses the right number.

A workaround (not a solution) would be to have a global array filled with structs that each has a reference to a tileset and a to their tile width and height... but I would like to avoid this workaround because of how it is error prone and I need to manually update it whenever I make some change in the tilesets or create/delete some tileset.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
There is currently no way to retrieve the width of a single tile from a tileset asset (afaik). If you have different widths and heights for the tilesets you're probably going to have to create a map that maps the tileset name to it's cell width and then do the map lookup when creating the tilemap layer. I would also say that you should file a suggestion with YYG about getting a function added to retrieve the width/height of the cells in a tileset. We have tileset_get_name(), tileset_get_uvs and tileset_get_texture, yet no tilset_get_cell_width/height(). This seems like an oversight and is something I'd request get remedied as it's useful for procedural games.
 

Sam04

Member
There is currently no way to retrieve the width of a single tile from a tileset asset (afaik). If you have different widths and heights for the tilesets you're probably going to have to create a map that maps the tileset name to it's cell width and then do the map lookup when creating the tilemap layer. I would also say that you should file a suggestion with YYG about getting a function added to retrieve the width/height of the cells in a tileset. We have tileset_get_name(), tileset_get_uvs and tileset_get_texture, yet no tilset_get_cell_width/height(). This seems like an oversight and is something I'd request get remedied as it's useful for procedural games.
Too bad. Well, at least now I am sure I am doing the best possible solution. Thanks for your guidance.


Is this the function you're looking for: tilemap_get_tile_width?
Sorry, but no. That function is to get the width of a tile in a tilemap, I need the width of a tile in a tileset. But if only it were about tilesets that would be exactly what I need. Thanks for the attention.
 
Top