Skip to content
Modar Nasser edited this page Dec 14, 2024 · 16 revisions

In file LDtkLoader/Layer.hpp

Class : ldtk::Layer

A Layer is a part of a Level and can contain Tiles or Entities.

Fields

level

const ldtk::Level* ldtk::Layer::level

Pointer to the Level object that contains the Layer.

iid

const std::string ldtk::Layer::iid

Unique instance ID of the Layer.

🔝

Methods

getType

ldtk::Layer::getType() const -> const ldtk::LayerType&

Returns the type of the Layer (IntGrid, Entities, Tiles or AutoLayer).

🔝

getName

ldtk::Layer::getName() const -> const std::string&

Returns the name of the Layer.

🔝

isVisible

ldtk::Layer::isVisible() const -> bool

Returns true if the Layer is visible in the editor, returns false otherwise.

🔝

getCellSize

ldtk::Layer::getCellSize() const -> int

Returns the size of grid cells (cell_size x cell_size).

🔝

getGridSize

ldtk::Layer::getGridSize() const -> const ldtk::IntPoint&

Returns the size of the grid in cells (the width and height of the level in cells number, not in pixel).

🔝

getOffset

ldtk::Layer::getOffset() const -> const ldtk::IntPoint&

Returns Layer total offset in pixels.

🔝

getOpacity

ldtk::Layer::getOpacity() const -> float

Returns Layer opacity.

🔝

hasTileset

ldtk::Layer::hasTileset() const -> bool

Returns true if the Layer has a Tileset, returns false otherwise.

🔝

getTileset

ldtk::Layer::getTileset() const -> const ldtk::Tileset&

Returns the Tileset used by the Layer.

Throws an invalid_argument exception if Layer does not have a Tileset.

🔝

allTiles

ldtk::Layer::allTiles() const -> const std::vector<ldtk::Tile>&

Returns a vector containing all the Tiles in the Layer, ordered correctly.

🔝

getTile

ldtk::Layer::getTile(int x, int y) const -> const Tile&

Returns the Tile located at (x, y) grid position.

Returns ldtk::Tile::None if there is no tile at the position.

🔝

getTilesByEnumTag

ldtk::Layer::getTilesByEnumTag(const EnumValue&) const -> const std::vector<std::reference_wrapper<Tile>>&

Returns a vector containing reference wrappers of Tiles tagged with the given EnumValue.

Because the returned vector contains reference wrappers, using auto won't work as expected, you have to explicitly specify the type when iterating :

const auto& chest_enumval = world.getEnum("Items")["Chest"];
for (const ldtk::Tile& chest_tiles : layer.getTilesByEnumTag(chest_enumval)) {
    // ...
}

🔝

getIntGridVal

ldtk::Layer::getIntGridVal(int x, int y) const -> const IntGridValue&

Returns the IntGridValue value located at (x, y) grid position.

Returns ldtk::IntGridValue::None if there is no IntGridValue at the position.

🔝

getIntGridValPositions

ldtk::Layer::getIntGridValPositions(int value) const -> const std::vector<IntPoint>&

Returns a vector containing the grid positions of all tiles of the given IntGridValue value.


ldtk::Layer::getIntGridValPositions(const std::string& name) const -> const std::vector<IntPoint>&

Returns a vector containing the grid positions of all tiles of the given IntGridValue name.

🔝

hasEntity

ldtk::Layer::hasEntity(const std::string& name) const -> bool

Returns true if Layer has an Entity with the provided name, returns false otherwise.

🔝

allEntities

ldtk::Layer::allEntities() const -> const std::vector<Entity>&

Returns a vector containing all Entities of the Layer.

🔝

getEntitiesByName

ldtk::Layer::getEntitiesByName(const std::string& name) const -> const std::vector<std::reference_wrapper<Entity>>&

Returns a vector containing reference wrappers of Entities named as the provided name.

Because the returned vector contains reference wrappers, using auto won't work as expected, you have to explicitly specify the type when iterating :

for (const ldtk::Entity& slime : layer.getEntitiesByName("Slime")) {
    // ...
}

🔝

getEntitiesByTag

ldtk::Layer::getEntitiesByTag(const std::string& tag) const -> const std::vector<std::reference_wrapper<Entity>>&

Returns a vector containing reference wrappers of Entities tagged with the provided tag name.

Because the returned vector contains reference wrappers, using auto won't work as expected, you have to explicitly specify the type when iterating :

for (const ldtk::Entity& actionable : layer.getEntitiesByTag("actionable")) {
    // ...
}

🔝

Clone this wiki locally