• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker get tileset width and height?

S

Shadowblitz16

Guest
does anybody know how to get a tilesets size? I need it for getting the length of the tileset
 
M

MarceloP

Guest
Actually, i'm on the same boat.... It doesn't seem to be a way of doing that. Neither the sprite of the tileset resource, in such a way that I could get it from there.
 

Amon

Member
If you know the width and height of the tile just multiply it by how many frames are in the tileset. So, if you had a tileset image with 8 frames, each frame 64x64 pixels just multiply 64 by 8 to get the width of the tileset. The height is easy. If there is one row then the height is 64. If there is 2 rows then the height is 128 etc
 
M

MarceloP

Guest
But there's also no function to get the number of frames from a tileset =(

I mean, all functions are related to the tilemap. But if I want to know how many rows and columns my tileset has, I can't...
https://docs2.yoyogames.com/source/_build/3_scripting/4_gml_reference/rooms/tilemaps/index.html

I can get a tilemap and check/grab the tileset ID that is in that tilemap. But there're no functions to check/work with tilesets (neither grab their sprites).

EDITED: I mean, I'll just abandon my neat idea, and do everything in my prototype in a different way, but I think that from the extensions and maketplace perspectives, not having those functions that work with the tileset based on its width and height may be pretty bad. Not always what you want is in the tilemap...
 
Last edited by a moderator:
T

tomsaram

Guest
Why would you want to get the size of the tileset? Perhaps we can think of some workarounds.
 
M

MarceloP

Guest
Well, knowing the size of the tileset and divinding it by the tile size I'd have how many rows and columns my tileset has. With that I can get the Data from the Tileset Index with TileSetGet or even TileIndex and know exactly witch tile I'm talking about.
I wanted to write a script that, with a specific tileset cell (x and y) I'd transform that in the index. It'd pretty simple since the index is the position of the cell, but it is added one column and one row, since game maker adds those when creating a tileset since it requires the top left on to be an empty tile.

I can simply abandon all that an do it by hand. But since we make a lot of games here in my company, having an easy way to figure out the tile and it's index would be perfect. Not having a way to work with the tilset resource is wayyy too bad.
 

Slyddar

Member
I'm looking for a way to do this as well. So is there still no function, or method, to get the width of a Tile Set?

Even if there was a function like sprite_get_name() / object_get_name(), etc, something like tileset_get_name() that you could use to get the name of the sprite assigned to the tileset. We could then get the width of the sprite and divide it by
tilemap_get_tile_width() to get how many tiles wide it is.
 

Slyddar

Member
Has anyone found a solution for this?
It seems the problem is you are not able to get the width/height of a tileset, and when you try to refer to the tile sprite using sprite functions, it returns -1. So I've found if you make a copy of the tile sprite, you can perform sprite functions and then tile functions together and get the size of the tileset that way.

EDIT: As suggested below, you don't need to make a copy, just use my code but in the tile set, uncheck Disable Source Sprite Export. Kudos to @RhyminGarFunkle for that refinement.
Code:
//how many tiles wide/high the tileset is, based on the sprite s_tile
var w = sprite_get_width(s_tile)/tilemap_get_tile_width(tilemap);
var h = sprite_get_height(s_tile)/tilemap_get_tile_height(tilemap);
show_debug_message("Width : " + string(w) + ", Height: " + string(h));
 
Last edited:
Open the tileset resource, and on the right side you'll see the tileset properties. The last option there is a checkbox, "Disable Source Sprite Export". It's checked by default but if you uncheck it you can access the sprite resource and the tileset resource in-game without needing to make a copy, which will make TheSly's solution a little cleaner.
 
Top