• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code Create Tile Sets through code

NazGhuL

NazTaiL
Hi! Can you create a Tile Set resource on the fly?
Let say you have 5 sprite: a black dungeon, red, green, yellow and white.
One sprite for each. Do you have to manually(in the ide) create a tile set for each dungeon sprite?
I looked in the manual and failed to find something revelant to me.
I know how to asign a different tile set to a layer but not a sprite to a tile set.
(perhaps sprite_asign... ?)
 

mMcFab

Member
As far as I can tell - no.
For now you need to create multiple sprites and tilesets and use tilemap_tileset - I think the tiledata in the layer is still the same, so it will still update to the new tiles. As far as I can tell, at compile time sprites and tiles become two totally separate things (as well as the addition of bleeding to prevent seams), so it seems unlikely that tilesets will be allowed to have sprites assigned at runtime.
I could be wrong, though, and a dev may turn up and say it's perfectly possible ;)

Technically speaking, though, you could recreate tilemaps using buffers, sprite_draw_part and a little bit of information about tile size and separation in order to use sprites as tiles at runtime
 
Last edited:

mdbussen

Member
For whatever its worth I would love to see more GML tileset functions, to allow us to manipulate the tileset data or access tileset information through code. *IF* it is not too much hassle I think it would be a really worthwhile addition.

I posted this in a separate thread yesterday but I couldn't find anyway to figure out how many tiles are in an arbitrary tileset, aside from using the base sprite 'sprite_get_width()' function, dividing by the tile size, and subtracting 1 (for the "blank" tile). Would be much nicer if there was a built-in function for this ;)
 

Mike

nobody important
GMC Elder
You have to create the tileset in the IDE, but you an swap the tileset a tilemap uses at runtime, or create a new new tilemap using any IDE created tileset. Since the tiledata is the same (regardless of tileset, or tile size), you can aslo "copy" tiledata from one tilemap into another using a different tileset if you like.

Tilesets are not just a grid of tiles since we add rendering borders to them, and they won't then fit within the space space. These rendering borders are required for tilesets to work correctly. In theory you could have a sprite or surface with all this info and have a dynamic "tileset" creation, however, this is not something we're looking to do any time soon.
 

Jyrocity

Member
@Mike This limitation is greatly impacting a project of mine. I would like to create tilesets from a surface that has been drawn to. I can create a sprite from the surface, but there is no way to indicate that I want this sprite to be a tileset with a 16 x 16 pixel gridsize. If I remember correctly, this function was available in previous versions of game maker? Please consider adding this functionality, or if you could let me know a workaround that would be great!
 

Jyrocity

Member
@Mike & @rwkay Here is a related question; would layer_sprite_create(layer_id, x, y, sprite) be an alternate workaround? Instead of creating a tileset, I would create a number of sprites (all 16 x 16) which would represent each tile, and they would be added to a layer using this function.
My question is; would this be, cell for cell, as fast as adding tiles? apples to apples comparison, would this use up just as much memory as well?
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
My question is; would this be, cell for cell, as fast as adding tiles? apples to apples comparison, would this use up just as much memory as well?
No. It would be the equivalent of using the "old" tile system (ie: the system used by all previous versions of GM). For performance you can think of it like this: That said, using sprites is indeed a viable option imho, as while they are still faster to process than instances, and while the old tile system was not as optimised ad the new, it was still pretty fast! As for memory, I would assume it'll use more as more information is required for each tile (sprite), but it'll still be less than if you used instances... although I wouldn't worry too much about memory unless your game is already pushing the limits (which very few GM games have done...)
 

Nikles

Member
Hey @rwkay, sorry for this thread necromancy, but with the advent of new GMS 2.3.1 features (JSON <-> structs) and the surfacing of open source tools like the Level Design ToolKit (LDtk) that save in JSON format, the lack of runtime tileset creation is becoming more and more... noticeable.

Real use case:
I'm developing a game with my mate. He draws the tilesets and also does some major level design in LDtk while the game hot-reload the project reading it from the LDtk JSON. As of now, unfortunately, everytime he changes the tilesets, I have to reimport the asset in GMS2, create a new tileset, discuss with him a naming convention and tweak the parser accordingly.

Having runtime tileset creation functions would not only speed up our development, but open up the game to some serious modding.
Should I open a feature request somewhere or are you already considering this?
 

Autobob

Member
I'm having a very similar issue. My artist likes to design levels and tilesets using the Tiled map creator, and I'd like to be able to directly import his new tiles without having to recreate the tilesets in the IDE.
 
Top