TileSetScenesCollectionSource

继承: TileSetSource < Resource < RefCounted < Object

Exposes a set of scenes as tiles for a TileSet resource.

描述

When placed on a TileMap, tiles from TileSetScenesCollectionSource will automatically instantiate an associated scene at the cell's position in the TileMap.

Scenes are instantiated as children of the TileMap when it enters the tree. If you add/remove a scene tile in the TileMap that is already inside the tree, the TileMap 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);
        }
    }

方法


方法说明

int create_scene_tile ( packed_scene: PackedScene, id_override: int = -1 )

Creates a scene-based tile out of the given scene.

Returns a newly generated unique ID.


int get_next_scene_tile_id ( ) const1

Returns the scene ID a following call to create_scene_tile would return.


bool get_scene_tile_display_placeholder ( id: int ) const1

Returns whether the scene tile with id displays a placeholder in the editor.


int get_scene_tile_id ( index: int )

Returns the scene tile ID of the scene tile at index.


PackedScene get_scene_tile_scene ( id: int ) const1

Returns the PackedScene resource of scene tile with id.


int get_scene_tiles_count ( )

Returns the number or scene tiles this TileSet source has.


bool has_scene_tile_id ( id: int )

Returns whether this TileSet source has a scene tile with id.


void remove_scene_tile ( id: int )

Remove the scene tile with id.


void set_scene_tile_display_placeholder ( id: int, display_placeholder: bool )

Sets whether or not the scene tile with id should display a placeholder in the editor. This might be useful for scenes that are not visible.


void set_scene_tile_id ( id: int, new_id: int )

Changes a scene tile's ID from id to new_id. This will fail if there is already a tile with an ID equal to 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 TileMap.

2

本方法通常需要用户覆盖才能生效。

1

本方法无副作用,不会修改该实例的任何成员变量。

3

本方法除了能接受在此处描述的参数外,还能够继续接受任意数量的参数。

4

本方法用于构造某个类型。

5

调用本方法无需实例,可直接使用类名进行调用。

6

本方法描述的是使用本类型作为左操作数的有效运算符。

7

这个值是由下列位标志构成位掩码的整数。

8

无返回值。