Introduction

About

AutoTiles Helper is a set of scripts providing functionalities to expand compressed tilesets into a set of 47 tiles, and get their respective index when placed into a room based on adjacent tiles. You just have to provide the tileset, and the scritps will automatically figure out which tile is appropriate for a particular spot.

Installation

1. Open GameMaker: Studio, log in to the Marketplace and navigate to the Library tab. From there you can download and import the resources into your project.
2. Next, go into the extensions folder in the resource tree, double click the AutoTiles Helper extension and select the tab "Import resources".
3. The minimum resources you'll need are the contents of the "autotiles" folders in included files and in scripts. If you want to try the sample rooms just import all the contents into a blank project.

How to use

Initialize

Before using any other function, you need to init the system with autotiles_init(file), providing the path to the file holding the required system data.

autotiles_init("autotiles/autotiles_data.json");

The next thing you need is a compressed (sample) or expanded (sample) tileset. Remember that the final uncompressed tileset has a specific tile order that has to be followed or it won't work as expected. See the section Anatomy of a tile for more information.

Expanding a compressed tileset

If you have a compressed tileset like the above, the first thing to do is generate an expanded version. In order to do that you'll need to generate it by passing the tileset as background to the autotile_expand script.

expanded_tileset = autotile_expand(bk_tileset,8);

The result is a surface with the 47 tiles, in the case above having 8 tiles per row. You can save the result to file or use it on the fly to generate a sprite or a background (not suggested for performance reasons). Sample result:

Displaying the tiles

In the sample project, a tile is represented by an object having a sprite holding each tile as subimages, for a total of 47 subimages (created in this case on the fly from a compressed tileset).

Placing the instances of obj_tile into the room generates the correct tile image with respect to the adjacent tiles.

This is done by calling the autotile_get_index() script, which checks for the adjacent objects and returns the correct image index to display.

Anatomy of a tileset

While there are no constraints on how big your tileset can be, expanded and compressed tilesets need to be structured in a very specific way in order to be used with the provided scripts and resources.

Compressed tilesets

Compressed tilesets contain all the required information that allow to generate a full expanded tileset. Starting from one structured like the one above, by dividing and recombining it into smaller sections it's possible to generate the 47 tiles.

For a more detailed guide, refer to this post that explains the same structure as used in rpg maker.

Expanded tilesets

An expanded tileset contains all the 47 possible combinations in the correct order. The order is not set in stone, meaning that it's decided arbitrarily and subsequently taken into account when deciding which tile to display based on the adjacent tiles. The order used by this asset follows the one used by Game Maker 2.

Scripts reference

autotiles_init(file)

Loads the data required to expand tilesets and compute the tile index, stored in a json file. This needs to be called before any other function and only once per game run time.

autotiles_init("autotiles/autotiles_data.json");
autotile_expand(background,columns)

Returns a surface containing the 47 tiles generated from the provided background. columns defines how many tiles per row the resulting surface will hold.

expanded_wall = autotile_expand(bk_wall,8);
autotile_get_index([open_borders])

Returns the index of the tile for the object calling the script, considering therefore the adjacent instances of the same object. open_borders (options, default: false), if true considers the area outside of the room size to be filled with instances of the current tile, leaving therefore the tile "open".

image_index = autotile_get_index();

Credits

Contact me on the GMC forums or by email at simoneguerra<at>ekalia.com