Skip to content
Modar Nasser edited this page Jun 19, 2024 · 16 revisions

In file LDtkLoader/Level.hpp

Class : ldtk::Level

A Level represents a single tilemap in the World. It contains one or multiple Layers.

Fields

world

const ldtk::World* ldtk::Level::world

Pointer to the World object that contains the Level.

🔝

name

const std::string ldtk::Level::name

Name of the Level.

🔝

iid

const std::string ldtk::Level::iid

Unique instance ID of the Level.

🔝

uid

const int ldtk::Level::uid

Unique identifier of the Level.

🔝

size

const ldtk::IntPoint ldtk::Level::size

Size of the Level in pixels.

🔝

position

const ldtk::IntPoint ldtk::Level::position

Position in pixels of the Level relatively to the World.

🔝

bg_color

const ldtk::Color ldtk::Level::bg_color

Background color of the Level.

🔝

depth

const int ldtk::Level::depth

Depth of the Level. 0 by default.

🔝

Methods

allLayers

ldtk::Level::allLayers() const -> const std::vector<ldtk::Layer>&

Returns the vector containing all Layers of the Level.

🔝

getLayer

ldtk::Level::getLayer(const std::string& layer_name) const -> const ldtk::Layer&

Returns the Layer matching the given name.

If no Layer is found, an invalid_argument exception is thrown.

🔝

hasBgImage

ldtk::Level::hasBgImage() const -> bool

Returns true if the Level has a background image, returns false otherwise.

🔝

getBgImage

ldtk::Level::getBgImage() const -> const ldtk::BgImage&

Returns the background image data of the Level. See BgImage.

🔝

getNeighbours

ldtk::Level::getNeighbours(const Dir&) const -> const std::vector<ref_wrapper<const Level>>&

Returns a vector containing all the neighbour Levels placed at the given direction.

🔝

getNeighbourDirection

ldtk::Level::getNeighbourDirection(const ldtk::Level& level) const -> ldtk::Dir

Get the direction of a neighbour Level. If the given Level is not a neighbour, returns ldtk::Dir::None.

See Dir.

🔝

getField<T>

Inherited from FieldsContainer

template <FieldType T>
ldtk::Level::getField(const std::string& name) const -> const ldtk::getFieldType<T>&

Returns the field matching the given name and type. Returned field can be null.

T must be one of the values of the FieldType enum.

This overload allows to get either single value fields or array fields:

// get a single value field
const auto& field = entity.getField<ldtk::FieldType::Color>("hair_color");

if (!field.is_null()) {
    // get the field value
    const auto& hair_color = field.value();
}
// get an array field
const auto& array_field = level.getField<ldtk::FieldType::ArrayPoint>("spawns");

// iterate on the array field
for (const auto& field : array_field) {
    if (!field.is_null()) {
        // get the field value
        const auto& point = field.value();
    }
}

template <typename T>
ldtk::Level::getField(const std::string& name) const -> const ldtk::Field<T>&

Returns the field matching the given name and type. Returned field can be null.

T must be one of the following types : int, float, bool, std::string, ldtk::Color, ldtk::IntPoint, ldtk::Enum, ldtk::FilePath.

For example, if your Level has a field of type Color named "color", you can write :

const Level& object = ...; // get the Level

// get the field
const auto& field = object.getField<ldtk::Color>("color");

if (!field.is_null()) {
    // get the field value
    const auto& color = field.value();
}

🔝

getArrayField<T>

Inherited from FieldsContainer

template <typename T>
ldtk::Level::getArrayField(const std::string& name) const -> const ldtk::ArrayField<T>&

Returns the array field matching the given name and type.

ldtk::ArrayField<T> is equivalent to std::vector<ldtk::Field<T>> and can be iterated over like a normal vector. Fields can be null.

T must be one of the following types : int, float, bool, std::string, ldtk::Color, ldtk::IntPoint, ldtk::Enum, ldtk::FilePath.

For example, if your Level has a field of type ArrayPoint named "spawns", you can write :

const Level& object = ...; // get the Level

// get the field
const auto& array_field = object.getArrayField<ldtk::IntPoint>("spawns");

// iterate on the array field
for (const auto& field : array_field) {
    if (!field.is_null()) {
        // get the field value
        const auto& point = field.value();
    }
}

🔝

Clone this wiki locally