• 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 Copy Each Tile in Tilemaps and Produce Copy Maps Later

I need to collect data on what each tile is in tilemaps in order to remake the tilemaps later and perform a few operations on them. I also need to do this for how many ever tilemaps are in a room. Given that I have the data on which tilemaps exist in the room how do I store what each tile is, and for multiple tile layers (I know GM doesn't do 3d arrays). If even if you can only explain storing the individual tile data on one tilemap that you already know exists that may be helpful. Since the tiles will be numbers in the data reading it may be difficult unless arranged like xy cells, and how to do I order these number in a manor that looping through them will produce the tilemap again?
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
You will need to get the tilemap ID, then loop though it and extract the tile value and store it somehow. easiest would probably be a DS grid, as you can then call the ds_grid_write (and for loading, ds_grid_red) function to create a string which can be saved to a text file.This is really easy to do, but has a couple of down-sides. First the strings created could be pretty huge, as grid strings are large and hold a lot of extra padding. You'd also need to have a separate text or ini file for any extra data that each map requires (like tileset sprite, or width/height, etc...), and finally, the grid read/write functions are pretty slow....

A more efficient method would be to use a buffer for each layer of tiles, as that way you could also store the tileset being used and any other extra information. For example, if the tilemaps are an arbitrary size, then the first values in the buffer could be tilemap width (in cells), tilemap height (in cells), cell width, cell height, and tileset. So you'd write those bits to a buffer, then sequentially write out each cell tile index from the tilemap using a couple of "for" loops. This can then be read back in again, and you'd use the initial information to get the correct settings for the read "for" loops and sequentially recreate the tilemap.
 
You will need to get the tilemap ID, then loop though it and extract the tile value and store it somehow. easiest would probably be a DS grid, as you can then call the ds_grid_write (and for loading, ds_grid_red) function to create a string which can be saved to a text file.This is really easy to do, but has a couple of down-sides. First the strings created could be pretty huge, as grid strings are large and hold a lot of extra padding. You'd also need to have a separate text or ini file for any extra data that each map requires (like tileset sprite, or width/height, etc...), and finally, the grid read/write functions are pretty slow....

A more efficient method would be to use a buffer for each layer of tiles, as that way you could also store the tileset being used and any other extra information. For example, if the tilemaps are an arbitrary size, then the first values in the buffer could be tilemap width (in cells), tilemap height (in cells), cell width, cell height, and tileset. So you'd write those bits to a buffer, then sequentially write out each cell tile index from the tilemap using a couple of "for" loops. This can then be read back in again, and you'd use the initial information to get the correct settings for the read "for" loops and sequentially recreate the tilemap.
I won't need to save the tilemaps to a file, just keep it in memory (sometimes between rooms) so I can copy it during the game. Not sure how I'll store an unknown number of tile layers in 1 object and what's in each tile slot in them without a 3d array, or data structure, so that I can loop through all of that to copy them all.

Edit: Ok I tried to nest a 2d array in a 1d one. When running the file the first draw text line is the 2d array and second draw text line the nested array. It's not working though as it just copied the values from the 2nd layer twice. I should get the first layer then the second. What's going wrong here?

Tilemap Gather Test 1
https://www.dropbox.com/s/v55elr7brd73tcd/Gather Tilemap Test 1.yyz?dl=0
 
Last edited:
Top