Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
TileSet
繼承: Resource < RefCounted < Object
Tilemap 的圖塊庫。
說明
A TileSet is a library of tiles for a TileMapLayer. A TileSet handles a list of TileSetSource, each of them storing a set of tiles.
Tiles can either be from a TileSetAtlasSource, which renders tiles out of a texture with support for physics, navigation, etc., or from a TileSetScenesCollectionSource, which exposes scene-based tiles.
Tiles are referenced by using three IDs: their source ID, their atlas coordinates ID, and their alternative tile ID.
A TileSet can be configured so that its tiles expose more or fewer properties. To do so, the TileSet resources use property layers, which you can add or remove depending on your needs.
For example, adding a physics layer allows giving collision shapes to your tiles. Each layer has dedicated properties (physics layer and mask), so you may add several TileSet physics layers for each type of collision you need.
See the functions to add new layers for more information.
教學
屬性
|
||
|
||
|
||
|
||
|
方法
void |
add_custom_data_layer(to_position: int = -1) |
void |
add_navigation_layer(to_position: int = -1) |
void |
add_occlusion_layer(to_position: int = -1) |
add_pattern(pattern: TileMapPattern, index: int = -1) |
|
void |
add_physics_layer(to_position: int = -1) |
add_source(source: TileSetSource, atlas_source_id_override: int = -1) |
|
void |
add_terrain(terrain_set: int, to_position: int = -1) |
void |
add_terrain_set(to_position: int = -1) |
void |
|
void |
clear_terrains(terrain_set: int) |
void |
|
get_alternative_level_tile_proxy(source_from: int, coords_from: Vector2i, alternative_from: int) |
|
get_coords_level_tile_proxy(source_from: int, coords_from: Vector2i) |
|
get_custom_data_layer_by_name(layer_name: String) const |
|
get_custom_data_layer_name(layer_index: int) const |
|
get_custom_data_layer_type(layer_index: int) const |
|
get_custom_data_layers_count() const |
|
get_navigation_layer_layer_value(layer_index: int, layer_number: int) const |
|
get_navigation_layer_layers(layer_index: int) const |
|
get_navigation_layers_count() const |
|
get_next_source_id() const |
|
get_occlusion_layer_light_mask(layer_index: int) const |
|
get_occlusion_layer_sdf_collision(layer_index: int) const |
|
get_occlusion_layers_count() const |
|
get_pattern(index: int = -1) |
|
get_physics_layer_collision_layer(layer_index: int) const |
|
get_physics_layer_collision_mask(layer_index: int) const |
|
get_physics_layer_collision_priority(layer_index: int) const |
|
get_physics_layer_physics_material(layer_index: int) const |
|
get_physics_layers_count() const |
|
get_source(source_id: int) const |
|
get_source_count() const |
|
get_source_id(index: int) const |
|
get_source_level_tile_proxy(source_from: int) |
|
get_terrain_color(terrain_set: int, terrain_index: int) const |
|
get_terrain_name(terrain_set: int, terrain_index: int) const |
|
get_terrain_set_mode(terrain_set: int) const |
|
get_terrain_sets_count() const |
|
get_terrains_count(terrain_set: int) const |
|
has_alternative_level_tile_proxy(source_from: int, coords_from: Vector2i, alternative_from: int) |
|
has_coords_level_tile_proxy(source_from: int, coords_from: Vector2i) |
|
has_custom_data_layer_by_name(layer_name: String) const |
|
has_source(source_id: int) const |
|
has_source_level_tile_proxy(source_from: int) |
|
map_tile_proxy(source_from: int, coords_from: Vector2i, alternative_from: int) const |
|
void |
move_custom_data_layer(layer_index: int, to_position: int) |
void |
move_navigation_layer(layer_index: int, to_position: int) |
void |
move_occlusion_layer(layer_index: int, to_position: int) |
void |
move_physics_layer(layer_index: int, to_position: int) |
void |
move_terrain(terrain_set: int, terrain_index: int, to_position: int) |
void |
move_terrain_set(terrain_set: int, to_position: int) |
void |
remove_alternative_level_tile_proxy(source_from: int, coords_from: Vector2i, alternative_from: int) |
void |
remove_coords_level_tile_proxy(source_from: int, coords_from: Vector2i) |
void |
remove_custom_data_layer(layer_index: int) |
void |
remove_navigation_layer(layer_index: int) |
void |
remove_occlusion_layer(layer_index: int) |
void |
remove_pattern(index: int) |
void |
remove_physics_layer(layer_index: int) |
void |
remove_source(source_id: int) |
void |
remove_source_level_tile_proxy(source_from: int) |
void |
remove_terrain(terrain_set: int, terrain_index: int) |
void |
remove_terrain_set(terrain_set: int) |
void |
set_alternative_level_tile_proxy(source_from: int, coords_from: Vector2i, alternative_from: int, source_to: int, coords_to: Vector2i, alternative_to: int) |
void |
set_coords_level_tile_proxy(source_from: int, coords_from: Vector2i, source_to: int, coords_to: Vector2i) |
void |
set_custom_data_layer_name(layer_index: int, layer_name: String) |
void |
set_custom_data_layer_type(layer_index: int, layer_type: Variant.Type) |
void |
set_navigation_layer_layer_value(layer_index: int, layer_number: int, value: bool) |
void |
set_navigation_layer_layers(layer_index: int, layers: int) |
void |
set_occlusion_layer_light_mask(layer_index: int, light_mask: int) |
void |
set_occlusion_layer_sdf_collision(layer_index: int, sdf_collision: bool) |
void |
set_physics_layer_collision_layer(layer_index: int, layer: int) |
void |
set_physics_layer_collision_mask(layer_index: int, mask: int) |
void |
set_physics_layer_collision_priority(layer_index: int, priority: float) |
void |
set_physics_layer_physics_material(layer_index: int, physics_material: PhysicsMaterial) |
void |
set_source_id(source_id: int, new_source_id: int) |
void |
set_source_level_tile_proxy(source_from: int, source_to: int) |
void |
set_terrain_color(terrain_set: int, terrain_index: int, color: Color) |
void |
set_terrain_name(terrain_set: int, terrain_index: int, name: String) |
void |
set_terrain_set_mode(terrain_set: int, mode: TerrainMode) |
列舉
enum TileShape: 🔗
TileShape TILE_SHAPE_SQUARE = 0
矩形圖塊形狀。
TileShape TILE_SHAPE_ISOMETRIC = 1
Diamond tile shape (for isometric look).
Note: Isometric TileSet works best if all sibling TileMapLayers and their parent inheriting from Node2D have Y-sort enabled.
TileShape TILE_SHAPE_HALF_OFFSET_SQUARE = 2
矩形圖塊形狀,每隔一行/列偏移半個圖塊。
TileShape TILE_SHAPE_HEXAGON = 3
六邊形圖塊形狀。
enum TileLayout: 🔗
TileLayout TILE_LAYOUT_STACKED = 0
圖塊座標佈局,兩個軸與對應的局部水平軸和垂直軸保持一致。
TileLayout TILE_LAYOUT_STACKED_OFFSET = 1
與 TILE_LAYOUT_STACKED 相同,但第一個半偏移偏向負方向,而不是正方向。
TileLayout TILE_LAYOUT_STAIRS_RIGHT = 2
圖塊座標佈局,水平軸保持水平,垂直軸朝向右下方。
TileLayout TILE_LAYOUT_STAIRS_DOWN = 3
圖塊座標佈局,垂直軸保持垂直,水平軸朝向右下方。
TileLayout TILE_LAYOUT_DIAMOND_RIGHT = 4
圖塊座標佈局,水平軸朝向右上方,垂直軸朝向右下方。
TileLayout TILE_LAYOUT_DIAMOND_DOWN = 5
圖塊座標佈局,水平軸朝向右下方,垂直軸朝向左下方。
enum TileOffsetAxis: 🔗
TileOffsetAxis TILE_OFFSET_AXIS_HORIZONTAL = 0
水平半偏移。
TileOffsetAxis TILE_OFFSET_AXIS_VERTICAL = 1
垂直半偏移。
enum CellNeighbor: 🔗
CellNeighbor CELL_NEIGHBOR_RIGHT_SIDE = 0
右側相鄰儲存格。
CellNeighbor CELL_NEIGHBOR_RIGHT_CORNER = 1
右角相鄰儲存格。
CellNeighbor CELL_NEIGHBOR_BOTTOM_RIGHT_SIDE = 2
右下側相鄰儲存格。
CellNeighbor CELL_NEIGHBOR_BOTTOM_RIGHT_CORNER = 3
右下角相鄰儲存格。
CellNeighbor CELL_NEIGHBOR_BOTTOM_SIDE = 4
下側相鄰儲存格。
CellNeighbor CELL_NEIGHBOR_BOTTOM_CORNER = 5
下角相鄰儲存格。
CellNeighbor CELL_NEIGHBOR_BOTTOM_LEFT_SIDE = 6
左下側相鄰儲存格。
CellNeighbor CELL_NEIGHBOR_BOTTOM_LEFT_CORNER = 7
左下角相鄰儲存格。
CellNeighbor CELL_NEIGHBOR_LEFT_SIDE = 8
左側相鄰儲存格。
CellNeighbor CELL_NEIGHBOR_LEFT_CORNER = 9
左角相鄰儲存格。
CellNeighbor CELL_NEIGHBOR_TOP_LEFT_SIDE = 10
左上側相鄰儲存格。
CellNeighbor CELL_NEIGHBOR_TOP_LEFT_CORNER = 11
左上角相鄰儲存格。
CellNeighbor CELL_NEIGHBOR_TOP_SIDE = 12
上側相鄰儲存格。
CellNeighbor CELL_NEIGHBOR_TOP_CORNER = 13
上角相鄰儲存格。
CellNeighbor CELL_NEIGHBOR_TOP_RIGHT_SIDE = 14
右上側相鄰儲存格。
CellNeighbor CELL_NEIGHBOR_TOP_RIGHT_CORNER = 15
右上角相鄰儲存格。
enum TerrainMode: 🔗
TerrainMode TERRAIN_MODE_MATCH_CORNERS_AND_SIDES = 0
要求與相鄰圖塊地形的角和邊都配對。
TerrainMode TERRAIN_MODE_MATCH_CORNERS = 1
要求與相鄰圖塊地形的角相配對。
TerrainMode TERRAIN_MODE_MATCH_SIDES = 2
要求與相鄰圖塊地形的邊相配對。
屬性說明
TileLayout tile_layout = 0 🔗
void set_tile_layout(value: TileLayout)
TileLayout get_tile_layout()
For all half-offset shapes (Isometric, Hexagonal and Half-Offset square), changes the way tiles are indexed in the TileMapLayer grid.
TileOffsetAxis tile_offset_axis = 0 🔗
void set_tile_offset_axis(value: TileOffsetAxis)
TileOffsetAxis get_tile_offset_axis()
對於所有半偏移形狀(等軸、六邊形和半偏移正方形),確定偏移軸。
圖塊的形狀。
Vector2i tile_size = Vector2i(16, 16) 🔗
圖塊的大小,單位為圖元。無論圖塊是什麼形狀,這個大小對應的都是圖塊形狀的包圍矩形。因此,這是合集所需的最小儲存格大小。
算繪圖塊時啟用/禁用 UV 裁剪。
方法說明
void add_custom_data_layer(to_position: int = -1) 🔗
在 TileSet 中新增自訂資料層,放置到陣列中的 to_position 位置。如果 to_position 為 -1,則會將其新增到陣列的末尾。
自訂資料層能夠為合集圖塊分配自訂屬性。
在 TileSet 中新增導覽層,放置到陣列中的 to_position 位置。如果 to_position 為 -1,則會將其新增到陣列的末尾。
導覽層能夠為合集圖塊分配導覽區域。
void add_occlusion_layer(to_position: int = -1) 🔗
在 TileSet 中新增遮擋層,放置到陣列中的 to_position 位置。如果 to_position 為 -1,則會將其新增到陣列的末尾。
遮擋層能夠為合集圖塊分配遮擋多邊形。
int add_pattern(pattern: TileMapPattern, index: int = -1) 🔗
新增儲存在 TileSet 資源中的 TileMapPattern。如果提供了 index,則會插入到給定的位置。
void add_physics_layer(to_position: int = -1) 🔗
在 TileSet 中新增實體層,放置到陣列中的 to_position 位置。如果 to_position 為 -1,則會將其新增到陣列的末尾。
實體層能夠為合集圖塊分配碰撞多邊形。
int add_source(source: TileSetSource, atlas_source_id_override: int = -1) 🔗
在 TileSet 中新增 TileSetSource。如果 atlas_source_id_override 不為 -1,則還會設定其源 ID。否則會自動生成唯一識別碼。
函式返回新增的源 ID,如果無法新增源則返回 -1。
警告:同一個源不能同時屬於兩個 TileSet。如果新增的源已經附加到其他 TileSet,則會在該那個 TileSet 中移除。
void add_terrain(terrain_set: int, to_position: int = -1) 🔗
在 TileSet 的 terrain_set 地形集中新增新的地形,放置到陣列中的 to_position 位置。如果 to_position 為 -1,則會將其新增到陣列的末尾。
void add_terrain_set(to_position: int = -1) 🔗
在 TileSet 新增新的地形集,放置到陣列中的 to_position 位置。如果 to_position 為 -1,則會將其新增到陣列的末尾。
void cleanup_invalid_tile_proxies() 🔗
清除指向無效圖塊的圖塊代理。
void clear_terrains(terrain_set: int) 🔗
Clears all terrain properties for the given terrain set.
void clear_tile_proxies() 🔗
清除所有圖塊代理。
Array get_alternative_level_tile_proxy(source_from: int, coords_from: Vector2i, alternative_from: int) 🔗
返回給定識別字的備選級代理。返回的陣列包含三個代理的目標識別字(源 ID、合集坐標 ID 和備選圖塊 ID)。
如果該 TileSet 沒有給定識別字的代理,則返回空陣列。
Array get_coords_level_tile_proxy(source_from: int, coords_from: Vector2i) 🔗
返回給定識別字的座標級代理。返回的陣列包含代理的兩個目標識別字(源 ID 和合集座標 ID)。
如果該 TileSet 沒有給定識別字的代理,則返回空陣列。
int get_custom_data_layer_by_name(layer_name: String) const 🔗
返回自訂資料層的索引,該自訂資料層由名稱表示。
String get_custom_data_layer_name(layer_index: int) const 🔗
返回自訂資料層的名稱,該自訂資料層由索引表示。
Variant.Type get_custom_data_layer_type(layer_index: int) const 🔗
返回自訂資料層的型別,該自訂資料層由索引表示。
int get_custom_data_layers_count() const 🔗
返回自訂資料層的數量。
返回由給定的 layer_index 標識的 TileSet 導覽資料層是否啟用了指定的導航層,導覽層 layer_number 在 1 和 32 之間。
返回給定 TileSet 導覽層的(導覽伺服器中的)導覽層。
返回導覽層的數量。
int get_next_source_id() const 🔗
Returns a new unused source ID. This generated ID is the same that a call to add_source() would return.
int get_occlusion_layer_light_mask(layer_index: int) const 🔗
返回遮擋層的光照遮罩。
bool get_occlusion_layer_sdf_collision(layer_index: int) const 🔗
返回這個層的遮擋器是否使用 sdf_collision。
int get_occlusion_layers_count() const 🔗
返回遮擋層的數量。
TileMapPattern get_pattern(index: int = -1) 🔗
返回給定 index 處的 TileMapPattern。
返回此圖塊集處理的 TileMapPattern 的數量。
int get_physics_layer_collision_layer(layer_index: int) const 🔗
返回給定 TileSet 實體層中的物體所在的(物理伺服器中的)碰撞層。
int get_physics_layer_collision_mask(layer_index: int) const 🔗
返回給定 TileSet 實體層中物體的碰撞遮罩。
float get_physics_layer_collision_priority(layer_index: int) const 🔗
Returns the collision priority of bodies on the given TileSet's physics layer.
PhysicsMaterial get_physics_layer_physics_material(layer_index: int) const 🔗
返回給定 TileSet 實體層中物體的碰撞材質。
int get_physics_layers_count() const 🔗
返回實體層的數量。
TileSetSource get_source(source_id: int) const 🔗
返回 ID 為 source_id 的 TileSetSource。
int get_source_count() const 🔗
返回該 TileSet 中 TileSetSource 的數量。
int get_source_id(index: int) const 🔗
返回索引為 index 的源的源 ID。
int get_source_level_tile_proxy(source_from: int) 🔗
返回給定源識別字的源級別代理。
如果 TileSet 沒有給定識別字的代理,則返回 -1。
Color get_terrain_color(terrain_set: int, terrain_index: int) const 🔗
返回地形的顏色。
String get_terrain_name(terrain_set: int, terrain_index: int) const 🔗
返回地形的名稱。
TerrainMode get_terrain_set_mode(terrain_set: int) const 🔗
返回地形集模式。
int get_terrain_sets_count() const 🔗
返回地形集的數量。
int get_terrains_count(terrain_set: int) const 🔗
返回給定地形集中的地形數。
bool has_alternative_level_tile_proxy(source_from: int, coords_from: Vector2i, alternative_from: int) 🔗
返回給定的識別字是否存在備選級別的代理。
bool has_coords_level_tile_proxy(source_from: int, coords_from: Vector2i) 🔗
返回給定的識別字是否存在座標級別的代理。
bool has_custom_data_layer_by_name(layer_name: String) const 🔗
Returns if there is a custom data layer named layer_name.
bool has_source(source_id: int) const 🔗
返回該 TileSet 中是否存在給定源 ID 的源。
bool has_source_level_tile_proxy(source_from: int) 🔗
返回給定的源 ID 是否存在源級別的代理。
Array map_tile_proxy(source_from: int, coords_from: Vector2i, alternative_from: int) const 🔗
根據配置的代理,將提供的識別字對應到一組新的識別字。返回的是由源 ID、合集坐標 ID 和備選圖塊 ID 這三個元素構成的 Array。
這個函式首先搜尋配對的備選級代理,然後是座標級代理,然後是源級代理。
如果未找到與提供的識別字對應的代理,則返回與用作參數的值相同的值。
void move_custom_data_layer(layer_index: int, to_position: int) 🔗
將索引為 layer_index 的自訂資料層移動到陣列中給定的 to_position 位置。還會更新相應的合集圖塊。
將索引為 layer_index 的導覽層移動到陣列中給定的 to_position 位置。還會更新相應的合集圖塊。
void move_occlusion_layer(layer_index: int, to_position: int) 🔗
將索引為 layer_index 的遮擋層移動到陣列中給定的 to_position 位置。還會更新相應的合集圖塊。
void move_physics_layer(layer_index: int, to_position: int) 🔗
將索引為 layer_index 的實體層移動到陣列中給定的 to_position 位置。還會更新相應的合集圖塊。
void move_terrain(terrain_set: int, terrain_index: int, to_position: int) 🔗
將地形集 terrain_set 中索引為 terrain_index 的地形移動到陣列中給定的 to_position 位置。還會更新相應的合集圖塊。
void move_terrain_set(terrain_set: int, to_position: int) 🔗
將索引為 terrain_set 的地形集移動到陣列中給定的 to_position 位置。還會更新相應的合集圖塊。
void remove_alternative_level_tile_proxy(source_from: int, coords_from: Vector2i, alternative_from: int) 🔗
移除具有給定識別字的備選級別代理。
void remove_coords_level_tile_proxy(source_from: int, coords_from: Vector2i) 🔗
移除具有給定識別字的座標級別代理。
void remove_custom_data_layer(layer_index: int) 🔗
移除索引為 layer_index 的自訂資料層。也會相應地更新合集中的圖塊。
移除索引為 layer_index 的導覽層。也會相應地更新合集中的圖塊。
void remove_occlusion_layer(layer_index: int) 🔗
移除索引為 layer_index 的遮擋層。也會相應地更新合集中的圖塊。
void remove_pattern(index: int) 🔗
移除給定索引處的 TileMapPattern。
void remove_physics_layer(layer_index: int) 🔗
移除索引為 layer_index 的實體層。也會更新合集中的相應圖塊。
void remove_source(source_id: int) 🔗
移除具有給定源 ID 的源。
void remove_source_level_tile_proxy(source_from: int) 🔗
移除源級別的圖塊代理。
void remove_terrain(terrain_set: int, terrain_index: int) 🔗
移除給定地形集 terrain_set 中索引為 terrain_index 的地形。也會相應地更新合集中的圖塊。
void remove_terrain_set(terrain_set: int) 🔗
移除索引為 terrain_set 的地形集。也會相應地更新合集中的圖塊。
void set_alternative_level_tile_proxy(source_from: int, coords_from: Vector2i, alternative_from: int, source_to: int, coords_to: Vector2i, alternative_to: int) 🔗
Create an alternative-level proxy for the given identifiers. A proxy will map set of tile identifiers to another set of identifiers.
Proxied tiles can be automatically replaced in TileMapLayer nodes using the editor.
void set_coords_level_tile_proxy(source_from: int, coords_from: Vector2i, source_to: int, coords_to: Vector2i) 🔗
Creates a coordinates-level proxy for the given identifiers. A proxy will map set of tile identifiers to another set of identifiers. The alternative tile ID is kept the same when using coordinates-level proxies.
Proxied tiles can be automatically replaced in TileMapLayer nodes using the editor.
void set_custom_data_layer_name(layer_index: int, layer_name: String) 🔗
設定由給定索引標識的自訂資料層的名稱。名稱是層的識別字,因此如果名稱已被使用就會失敗並報告有錯。
void set_custom_data_layer_type(layer_index: int, layer_type: Variant.Type) 🔗
設定自訂資料層的型別,該自訂資料層由索引表示。
根據 value,啟用或禁用 TileSet 導覽資料層中指定的導覽層,導覽資料層由給定的 layer_index 標識,給定的 layer_number 應在 1 和 32 之間。
設定給定 TileSet 導覽層中導覽區域的導覽層(導覽伺服器中使用)。
void set_occlusion_layer_light_mask(layer_index: int, light_mask: int) 🔗
設定給定 TileSet 遮擋層中遮擋器的遮擋層(算繪伺服器中使用)。
void set_occlusion_layer_sdf_collision(layer_index: int, sdf_collision: bool) 🔗
啟用或禁用給定 TileSet 遮擋層中遮擋器的 SDF 碰撞。
void set_physics_layer_collision_layer(layer_index: int, layer: int) 🔗
Sets the collision layer (as in the physics server) for bodies in the given TileSet physics layer.
void set_physics_layer_collision_mask(layer_index: int, mask: int) 🔗
Sets the collision mask for bodies in the given TileSet physics layer.
void set_physics_layer_collision_priority(layer_index: int, priority: float) 🔗
Sets the collision priority for bodies in the given TileSet physics layer.
void set_physics_layer_physics_material(layer_index: int, physics_material: PhysicsMaterial) 🔗
設定給定 TileSet 實體層中物體的物理材質。
void set_source_id(source_id: int, new_source_id: int) 🔗
更改源的 ID。
void set_source_level_tile_proxy(source_from: int, source_to: int) 🔗
Creates a source-level proxy for the given source ID. A proxy will map set of tile identifiers to another set of identifiers. Both the atlas coordinates ID and the alternative tile ID are kept the same when using source-level proxies.
Proxied tiles can be automatically replaced in TileMapLayer nodes using the editor.
void set_terrain_color(terrain_set: int, terrain_index: int, color: Color) 🔗
設定地形的顏色。該顏色用於在 TileSet 編輯器中區分不同的地形。
void set_terrain_name(terrain_set: int, terrain_index: int, name: String) 🔗
設定地形的名稱。
void set_terrain_set_mode(terrain_set: int, mode: TerrainMode) 🔗
設定地形模式。每種模式決定了圖塊形狀的哪一個位被用來配對相鄰圖塊的地形。