-
Notifications
You must be signed in to change notification settings - Fork 28
Entity
Represents an Entity instance.
Tip
To get the correct sprite data of the Entity as it is shown in the editor,
you should use hasSprite to check if the Entity has a sprite,
and then getTexturePath and getTextureRect to get the texture data.
const Layer* const layerPointer to the Layer object that contains the Entity.
const std::string ldtk::Entity::iidUnique instance ID of the Entity.
getNamegetSizegetColorgetPositiongetGridPositiongetWorldPositiongetPivothasSpritegetTexturePathgetTextureRecthasNineSlicegetNineSliceBordershasTagallTagsgetField<T>getArrayField<T>
ldtk::Entity::getName() const -> const std::string&Returns the name of the Entity.
ldtk::Entity::getSize() const -> const ldtk::IntPoint&Returns the size in pixels of the Entity.
ldtk::Entity::getColor() const -> const ldtk::Color&Returns the color of the Entity.
ldtk::Entity::getPosition() const -> const ldtk::IntPoint&Returns the position in pixels of the Entity relative to the parent Layer.
If the layer has an offset different than (0, 0), the layer's total offset should be added to get the position in pixels relative to the parent Level :
auto entity_level_pos = entity.getPosition() + entity.layer->getOffset();ldtk::Entity::getGridPosition() const -> const ldtk::IntPoint&Returns the position in grid coordinates of the Entity.
ldtk::Entity::getWorldPosition() const -> const ldtk::IntPoint&Returns the computed position in pixels of the Entity relative to the World.
ldtk::Entity::getPivot() const -> const ldtk::FloatPoint&Returns the pivot of the Entity, a point from (0.f, 0.f) to (1.f, 1.f).
ldtk::Entity::hasSprite() const -> boolReturns true if the Entity has a sprite associated to it, returns false otherwise.
ldtk::Entity::getTexturePath() const -> const std::string&Returns the path to the texture of the sprite. Returns an empty string if the Entity has no sprite.
ldtk::Entity::getTextureRect() const -> const ldtk::IntRect&Returns the texture rectangle of this Entity's sprite.
ldtk::Entity::hasNineSlice() const -> boolReturns true if the Entity's sprite has a 9-slices scaling, returns false otherwise.
ldtk::Entity::getNineSliceBorders() const -> const ldtk::NineSliceBorders&Returns the Entity's 9-slices borders. See NineSliceBorders.
ldtk::Entity::hasTag(const std::string&) const -> boolReturns true if the Entity has the given tag, returns false otherwise.
ldtk::Entity::allTags() const -> const std::vector<std::string>&Returns a vector containing all tags of the Entity.
Inherited from FieldsContainer
template <FieldType T>
ldtk::Entity::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::Entity::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 Entity has a field of type Color named "color", you can write :
const Entity& object = ...; // get the Entity
// 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::Entity::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 Entity has a field of type ArrayPoint named "spawns", you can write :
const Entity& object = ...; // get the Entity
// 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();
}
}