此函数返回一个包含有关图块集信息的结构。
返回的结构包含以下变量:
变量名 | 数据类型 | 描述 |
---|---|---|
width | Real | 整个图块集纹理的宽度(像素) |
height | Real | 整个图块集纹理的高度(像素) |
texture | Real | 纹理 ID |
tile_width | Real | 单个图块的宽度(以像素为单位) |
tile_height | Real | 单个图块的高度(以像素为单位) |
tile_horizontal_separator | Real | 每个图块每一面的水平像素数 (使两个图块之间的间距为 2 * tile_horizontal_separator) |
tile_vertical_separator | Real | 每个图块每一面的垂直像素数 (使两个图块之间的间距为 2 * tile_vertical_separator) |
tile_columns | Real | 图块集每行上的列数 |
tile_count | Real | 图块数量 |
frame_count | Real | 每个动画的动画帧数 |
frame_length_ms | int64 (signed 64-bit integer) | 帧动画的毫秒数 |
frames | Struct | 包含所有动画帧的结构。每个图块编号在结构中都有一个键,每个条目都是要使用的帧的数组 (每个数组的长度应该是 frame_count)。 |
tileset_get_info(index);
参数 | 类型 | 描述 |
---|---|---|
index | Tile Set Asset | 要从中获取信息的图块集 |
图块集信息结构 (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);
上面的代码调用 tileset_get_info 以获取有关现有图块集 ts_Forest 的信息,并将结果存储在临时变量 _info 中。然后,该信息将显示在调试消息中。
// 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");
}
面的代码查找给定图块索引的左上角的坐标。首先,图块的索引被定义并存储在临时变量 _tnumber 中。然后 tileset_get_info 在现有磁贴集 ts_Forest 上调用并且返回的结构存储在 _ts_info 中。接下来,if 语句检查变量是否包含有效的结构(否则在接下来的步骤中访问变量将抛出错误)
如果包含,则会计算一些变量。_twidth 和 _theight 是图块集上的图块的总宽度和高度,包括两侧的边框(_ts_info.tile_horizontal_separator 和 _ts_info.tile_vertical_separator
_tile_x 是图块索引的剩余部分除以列数和 _tile_y 是 _ts_info.tile_columns 适应图块索引的次数。之后,将显示带有左上角坐标的调试消息(尚未包括分隔符偏移)
如果向函数提供了无效的图块集,则会显示不同的调试消息。