This function returns a struct containing information on a tile set.
The returned struct contains the following variables:
Variable Name | Data Type | Description |
---|---|---|
width | Real | The width of the whole tile set texture (in pixels) |
height | Real | The height of the whole tile set texture (in pixels) |
texture | Real | The texture ID |
tile_width | Real | The width of a single tile (in pixels) |
tile_height | Real | The height of a single tile (in pixels) |
tile_horizontal_separator | Real | The number of pixels horizontally on each side of each tile (making the space between two tiles 2 * tile_horizontal_separator) |
tile_vertical_separator | Real | The number of pixels vertically on each side of each tile (making the space between two tiles 2 * tile_vertical_separator) |
tile_columns | Real | The number of columns on each row of the tile set |
tile_count | Real | The number of tiles |
frame_count | Real | The number of frames of animation per animation |
frame_length_ms | int64 (signed 64-bit integer) | The number of milliseconds for frame animation |
frames | Struct | A 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). |
tileset_get_info(index);
Argument | Type | Description |
---|---|---|
index | Tile Set Asset | The tile set to get the info from |
Tile Set Info Struct (in case of a valid Tile Set Asset) or undefined (no valid tile set given)
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.
// 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.