-
Notifications
You must be signed in to change notification settings - Fork 28
Level
A Level represents a single tilemap in the World. It contains one or multiple Layers.
const ldtk::World* ldtk::Level::worldPointer to the World object that contains the Level.
const std::string ldtk::Level::nameName of the Level.
const std::string ldtk::Level::iidUnique instance ID of the Level.
const int ldtk::Level::uidUnique identifier of the Level.
const ldtk::IntPoint ldtk::Level::sizeSize of the Level in pixels.
const ldtk::IntPoint ldtk::Level::positionPosition in pixels of the Level relatively to the World.
const ldtk::Color ldtk::Level::bg_colorBackground color of the Level.
const int ldtk::Level::depthDepth of the Level. 0 by default.
allLayersgetLayerhasBgImagegetBgImagegetNeighboursgetNeighbourDirectiongetField<T>getArrayField<T>
ldtk::Level::allLayers() const -> const std::vector<ldtk::Layer>&Returns the vector containing all Layers of the Level.
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.
ldtk::Level::hasBgImage() const -> boolReturns true if the Level has a background image, returns false otherwise.
ldtk::Level::getBgImage() const -> const ldtk::BgImage&Returns the background image data of the Level. See BgImage.
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.
ldtk::Level::getNeighbourDirection(const ldtk::Level& level) const -> ldtk::DirGet the direction of a neighbour Level. If the given Level is not a neighbour, returns ldtk::Dir::None.
See Dir.
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();
}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();
}
}