tileset_get_info

This function returns a struct containing information on a tile set.

The returned struct contains the following variables: 

Tile Set Info Struct
Variable NameData TypeDescription
widthRealThe width of the whole tile set texture (in pixels)
heightRealThe height of the whole tile set texture (in pixels)
textureRealThe texture ID
tile_widthRealThe width of a single tile (in pixels)
tile_heightRealThe height of a single tile (in pixels)
tile_horizontal_separatorRealThe number of pixels horizontally on each side of each tile (making the space between two tiles 2 * tile_horizontal_separator)
tile_vertical_separatorRealThe number of pixels vertically on each side of each tile (making the space between two tiles 2 * tile_vertical_separator)
tile_columnsRealThe number of columns on each row of the tile set
tile_countRealThe number of tiles
frame_countRealThe number of frames of animation per animation
frame_length_msint64 (signed 64-bit integer)The number of milliseconds for frame animation
framesStructA struct containing all the animation frames. Each tile number has a key in the struct, each entry is an array of the frames to use (each array should be frame_count long).

 

Syntax:

tileset_get_info(index);

ArgumentTypeDescription
indexTile Set AssetThe tile set to get the info from

 

Returns:

Tile Set Info Struct (in case of a valid Tile Set Asset) or undefined (no valid tile set given)

 

Example 1: Showing the output 

var _info = tileset_get_info(ts_Forest);
show_debug_message(_info);

The above code calls tileset_get_info to get information about an existing tile set ts_Forest and stores the result in a temporary variable _info. The info is then shown in a debug message.

 

Example 2: Finding the top-left corner position of a tile

// tnumber is the number of the tile that you want to find
var _tnumber = 7;
var _ts_info = tileset_get_info(ts_Forest);
if (is_undefined(_ts_info) == false)
{
    var _twidth = _ts_info.tile_width + 2 * _ts_info.tile_horizontal_separator;
    var _theight = _ts_info.tile_height + 2 * _ts_info.tile_vertical_separator;
    var _tile_x = (_tnumber mod _ts_info.tile_columns) * _twidth;
    var _tile_y = (_tnumber div _ts_info.tile_columns) * _theight;
    show_debug_message("The top-left coordinates of tile index {0} are: ({1}, {2})", _tnumber, _tile_x, _tile_y);
}
else
{
    show_debug_message("No valid tile set was provided to the function");
}

The above code finds the coordinates of the top-left corner of the given tile index. First the index of the tile is defined and stored in a temporary variable _tnumber. Then tileset_get_info is called on an existing tile set ts_Forest and the returned struct is stored in _ts_info. Next an if statement checks if the variable contains a valid struct (accessing the variables in the next steps will throw errors otherwise).
If it does, some variables are calculated. _twidth and _theight are the total width and height of a tile on the tile set, including the border on both sides (_ts_info.tile_horizontal_separator and _ts_info.tile_vertical_separator) _tile_x is the remainder of the tile index divided by the number of columns and _tile_y is the number of times _ts_info.tile_columns fits into the tile index. After this, a debug message is shown with the top-left coordinates (the separator offsets not yet included).
If the case an invalid tile set was provided to the function a different debug message is shown.