Auto-Tile Help!

B

Butter

Guest
So in my game I have a random map created with tiles(grass, sand and water) and I want to have the tiles change based on the tiles next to them. Which is the auto-tile function, but the layer is created with the code and I cannot figure out how to get the tiles to auto-tile with code. Anyone know how to have something automatically auto-tile in game?
-Thanks for any answer'
 

jo-thijs

Member
So in my game I have a random map created with tiles(grass, sand and water) and I want to have the tiles change based on the tiles next to them. Which is the auto-tile function, but the layer is created with the code and I cannot figure out how to get the tiles to auto-tile with code. Anyone know how to have something automatically auto-tile in game?
-Thanks for any answer'
It would probably look something like this: group tiles together in categories (grass, sand and water).
Have a function that for a single tile checks the categories of the tiles in the 3x3 grid around the tile.
This function would basically store the category of each tile in the 3x3 grid in a 3x3 array.
Then a large nested switch-case structure can be used to specify the result for every combination.
If you structure your tiles cleverly, you might be able to significantly reduce the size of this switch-case code.
Finally, when (re)placing a tile, apply the function above for every tile in the 3x3 grid around the newly placed tile (so checks will be performed in a 5x5 grid).
Create a function for this and then always use this function to place tiles.

It's a bit tedious, but it is easy to implement and gets the job done.

You might find resources online of people that have already done this (as it is a very common task to do).
A quick google search on "GameMaker auto tile code" immediately gives:
https://forum.yoyogames.com/index.php?threads/draw-tiles-in-auto-tile-mode-through-code.20871/
The second one looks pretty good.
 
Top