Files
godot-docs/classes/class_tilesetsource.rst
2025-06-07 03:33:02 +00:00

146 lines
8.3 KiB
ReStructuredText

:github_url: hide
.. DO NOT EDIT THIS FILE!!!
.. Generated automatically from Godot engine sources.
.. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
.. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/TileSetSource.xml.
.. _class_TileSetSource:
TileSetSource
=============
**Inherits:** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
**Inherited By:** :ref:`TileSetAtlasSource<class_TileSetAtlasSource>`, :ref:`TileSetScenesCollectionSource<class_TileSetScenesCollectionSource>`
Exposes a set of tiles for a :ref:`TileSet<class_TileSet>` resource.
.. rst-class:: classref-introduction-group
Description
-----------
Exposes a set of tiles for a :ref:`TileSet<class_TileSet>` resource.
Tiles in a source are indexed with two IDs, coordinates ID (of type Vector2i) and an alternative ID (of type int), named according to their use in the :ref:`TileSetAtlasSource<class_TileSetAtlasSource>` class.
Depending on the TileSet source type, those IDs might have restrictions on their values, this is why the base **TileSetSource** class only exposes getters for them.
You can iterate over all tiles exposed by a TileSetSource by first iterating over coordinates IDs using :ref:`get_tiles_count()<class_TileSetSource_method_get_tiles_count>` and :ref:`get_tile_id()<class_TileSetSource_method_get_tile_id>`, then over alternative IDs using :ref:`get_alternative_tiles_count()<class_TileSetSource_method_get_alternative_tiles_count>` and :ref:`get_alternative_tile_id()<class_TileSetSource_method_get_alternative_tile_id>`.
\ **Warning:** **TileSetSource** can only be added to one TileSet at the same time. Calling :ref:`TileSet.add_source()<class_TileSet_method_add_source>` on a second :ref:`TileSet<class_TileSet>` will remove the source from the first one.
.. rst-class:: classref-reftable-group
Methods
-------
.. table::
:widths: auto
+---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`get_alternative_tile_id<class_TileSetSource_method_get_alternative_tile_id>`\ (\ atlas_coords\: :ref:`Vector2i<class_Vector2i>`, index\: :ref:`int<class_int>`\ ) |const| |
+---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`get_alternative_tiles_count<class_TileSetSource_method_get_alternative_tiles_count>`\ (\ atlas_coords\: :ref:`Vector2i<class_Vector2i>`\ ) |const| |
+---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`Vector2i<class_Vector2i>` | :ref:`get_tile_id<class_TileSetSource_method_get_tile_id>`\ (\ index\: :ref:`int<class_int>`\ ) |const| |
+---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`int<class_int>` | :ref:`get_tiles_count<class_TileSetSource_method_get_tiles_count>`\ (\ ) |const| |
+---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`bool<class_bool>` | :ref:`has_alternative_tile<class_TileSetSource_method_has_alternative_tile>`\ (\ atlas_coords\: :ref:`Vector2i<class_Vector2i>`, alternative_tile\: :ref:`int<class_int>`\ ) |const| |
+---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| :ref:`bool<class_bool>` | :ref:`has_tile<class_TileSetSource_method_has_tile>`\ (\ atlas_coords\: :ref:`Vector2i<class_Vector2i>`\ ) |const| |
+---------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
.. rst-class:: classref-section-separator
----
.. rst-class:: classref-descriptions-group
Method Descriptions
-------------------
.. _class_TileSetSource_method_get_alternative_tile_id:
.. rst-class:: classref-method
:ref:`int<class_int>` **get_alternative_tile_id**\ (\ atlas_coords\: :ref:`Vector2i<class_Vector2i>`, index\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_TileSetSource_method_get_alternative_tile_id>`
Returns the alternative ID for the tile with coordinates ID ``atlas_coords`` at index ``index``.
.. rst-class:: classref-item-separator
----
.. _class_TileSetSource_method_get_alternative_tiles_count:
.. rst-class:: classref-method
:ref:`int<class_int>` **get_alternative_tiles_count**\ (\ atlas_coords\: :ref:`Vector2i<class_Vector2i>`\ ) |const| :ref:`🔗<class_TileSetSource_method_get_alternative_tiles_count>`
Returns the number of alternatives tiles for the coordinates ID ``atlas_coords``.
For :ref:`TileSetAtlasSource<class_TileSetAtlasSource>`, this always return at least 1, as the base tile with ID 0 is always part of the alternatives list.
Returns -1 if there is not tile at the given coords.
.. rst-class:: classref-item-separator
----
.. _class_TileSetSource_method_get_tile_id:
.. rst-class:: classref-method
:ref:`Vector2i<class_Vector2i>` **get_tile_id**\ (\ index\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_TileSetSource_method_get_tile_id>`
Returns the tile coordinates ID of the tile with index ``index``.
.. rst-class:: classref-item-separator
----
.. _class_TileSetSource_method_get_tiles_count:
.. rst-class:: classref-method
:ref:`int<class_int>` **get_tiles_count**\ (\ ) |const| :ref:`🔗<class_TileSetSource_method_get_tiles_count>`
Returns how many tiles this atlas source defines (not including alternative tiles).
.. rst-class:: classref-item-separator
----
.. _class_TileSetSource_method_has_alternative_tile:
.. rst-class:: classref-method
:ref:`bool<class_bool>` **has_alternative_tile**\ (\ atlas_coords\: :ref:`Vector2i<class_Vector2i>`, alternative_tile\: :ref:`int<class_int>`\ ) |const| :ref:`🔗<class_TileSetSource_method_has_alternative_tile>`
Returns if the base tile at coordinates ``atlas_coords`` has an alternative with ID ``alternative_tile``.
.. rst-class:: classref-item-separator
----
.. _class_TileSetSource_method_has_tile:
.. rst-class:: classref-method
:ref:`bool<class_bool>` **has_tile**\ (\ atlas_coords\: :ref:`Vector2i<class_Vector2i>`\ ) |const| :ref:`🔗<class_TileSetSource_method_has_tile>`
Returns if this atlas has a tile with coordinates ID ``atlas_coords``.
.. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
.. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
.. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
.. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
.. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
.. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
.. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
.. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
.. |void| replace:: :abbr:`void (No return value.)`