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...
TileSetScenesCollectionSource
繼承: TileSetSource < Resource < RefCounted < Object
以圖塊的形式向 TileSet 資源暴露一組場景。
說明
When placed on a TileMapLayer, tiles from TileSetScenesCollectionSource will automatically instantiate an associated scene at the cell's position in the TileMapLayer.
Scenes are instantiated as children of the TileMapLayer after it enters the tree, at the end of the frame (their creation is deferred). If you add/remove a scene tile in the TileMapLayer that is already inside the tree, the TileMapLayer will automatically instantiate/free the scene accordingly.
Note: Scene tiles all occupy one tile slot and instead use alternate tile ID to identify scene index. TileSetSource.get_tiles_count() will always return 1. Use get_scene_tiles_count() to get a number of scenes in a TileSetScenesCollectionSource.
Use this code if you want to find the scene path at a given tile in TileMapLayer:
var source_id = tile_map_layer.get_cell_source_id(Vector2i(x, y))
if source_id > -1:
var scene_source = tile_map_layer.tile_set.get_source(source_id)
if scene_source is TileSetScenesCollectionSource:
var alt_id = tile_map_layer.get_cell_alternative_tile(Vector2i(x, y))
# The assigned PackedScene.
var scene = scene_source.get_scene_tile_scene(alt_id)
int sourceId = tileMapLayer.GetCellSourceId(new Vector2I(x, y));
if (sourceId > -1)
{
TileSetSource source = tileMapLayer.TileSet.GetSource(sourceId);
if (source is TileSetScenesCollectionSource sceneSource)
{
int altId = tileMapLayer.GetCellAlternativeTile(new Vector2I(x, y));
// The assigned PackedScene.
PackedScene scene = sceneSource.GetSceneTileScene(altId);
}
}
方法
create_scene_tile(packed_scene: PackedScene, id_override: int = -1) |
|
get_next_scene_tile_id() const |
|
get_scene_tile_display_placeholder(id: int) const |
|
get_scene_tile_id(index: int) |
|
get_scene_tile_scene(id: int) const |
|
has_scene_tile_id(id: int) |
|
void |
remove_scene_tile(id: int) |
void |
set_scene_tile_display_placeholder(id: int, display_placeholder: bool) |
void |
set_scene_tile_id(id: int, new_id: int) |
void |
set_scene_tile_scene(id: int, packed_scene: PackedScene) |
方法說明
int create_scene_tile(packed_scene: PackedScene, id_override: int = -1) 🔗
從給定的場景建立基於場景的圖塊。
返回新生成的唯一 ID。
int get_next_scene_tile_id() const 🔗
返回後續呼叫 create_scene_tile() 時會返回的場景 ID。
bool get_scene_tile_display_placeholder(id: int) const 🔗
返回 ID 為 id 的場景圖塊是否在編輯器中顯示占點陣圖。
int get_scene_tile_id(index: int) 🔗
返回索引為 index 的場景圖塊的場景圖塊 ID。
PackedScene get_scene_tile_scene(id: int) const 🔗
返回 ID 為 id 的場景圖塊的 PackedScene 資源。
返回該 TileSet 源中場景圖塊的數量。
bool has_scene_tile_id(id: int) 🔗
返回該 TileSet 源是否包含 ID 為 id 的場景圖塊。
void remove_scene_tile(id: int) 🔗
移除 ID 為 id 的場景圖塊。
void set_scene_tile_display_placeholder(id: int, display_placeholder: bool) 🔗
設定 ID 為 id 的場景圖塊是否應該在編輯器中顯示為預留位置。對不可見的場景可能有用。
void set_scene_tile_id(id: int, new_id: int) 🔗
將場景圖塊的 ID 從 id 改為 new_id。如果已經存在 ID 為 new_id 的圖塊則會失敗。
void set_scene_tile_scene(id: int, packed_scene: PackedScene) 🔗
Assigns a PackedScene resource to the scene tile with id. This will fail if the scene does not extend CanvasItem, as positioning properties are needed to place the scene on the TileMapLayer.