• 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 Tilesets and Dynamic Tiles

Turgon

Member
In GMS2 all the tileset and tile functions seem to have changed. After reading the available new documentation on the subject, I'm still rather confused about the practical application of how the new system works.

In previous versions of GM, a common method I would use is programmatically adding tiles during runtime using tile_add(...), etc. I do see that there are 'compatibility' functions available in GMS2 that let you do the same thing the same way, but I don't want to use legacy functions since that presumably means it is no longer the correct way to do things.

For example, right now I am making a random dungeon generator, and as the dungeon generates I'm trying to add tiles onto the appropriate tile layer, corresponding to the dungeon room floor, walls, etc. However I can't seem to figure out what the proper way to accomplish this is? It seems to me it should be an easy function that just adds the tile onto the tile layer programmatically, but I can't find that function if it exists.

Thanks for your help! Please help me to catch up with the times haha since I seem to be behind them with old-school methods.
 

Turgon

Member
Thanks for the quick reply @Lahssoo

So let's say I want to switch the tile at room position (120, 120) to display a tile at tilemap position(40, 40). Can you help me understand how to do that?

My current (not working) attempt, commented with my incorrect understanding of what each line does:
Code:
// understandable
lay_id = layer_get_id( "wall_tiles" ); // first get the layer id
map_id = layer_tilemap_get_id( lay_id ); // then from the layer, get the tilemap being used

// lost at these 4 steps
data = tilemap_get( map_id, 40, 40 ); // get the data of a tile image from the tilemap?
ind = tile_get_index( data ); //get the data of a tile image from the tilemap again?
data = tile_set_index( data,  ind ); // update the tilemap data with the new tile index?
tilemap_set( map_id, data, 120, 120 ); // update the room tile with the updated tilemap data?
1) tilemap_get( ... );
"Using this function you can retrieve the tile data from a cell of the tilemap element."
I think this means that it will return the data from the spritesheet of the actual tile image. E.g. a doorway tile.

2) tile_get_index( ... );
So after doing tilemap_get(), this function will return the index of which tile the doorway is on the tiled spritesheet?

3) tile_set_index( ... );
Intuitively this should set the index of which tile to show from the spritesheet, in the room tiles layer. But then why does it refer to the same tiledata as tilemap_get()? And why isn't there a way to tell the function which pixel coordinates to place the tile in the room?

4) tilemap_set( ... );
"This function can be used to set any cell (grid square) within the tilemap element on the layer to a new tile. "
I don't really understand this function at all unfortunately. It sounds simple - it would update the tile like I want? But then I don't understand the previous 3 steps.
 
Last edited:
L

Lahssoo

Guest
Well... To be honest, I've yet to even try the new tilemap system, ahahah... If nobody can help you by then, I'll take a few minutes in the afternoon to test that ^^;
 

YanBG

Member
I'd like to know more about GMS2's tile optimization too. In 1.4 i do get slowdowns when generate dungeon with tile_add(also read that they slow draw events too, even if you only placed them in create).
 
Top