Map of entity fields.
They can be accessed like regular properties.
For a full list of field types, see FieldType. All possible interfaces are under the Field union.
Usage:
import { FieldType } from "ldtk";
const entity = ... ;
for (const field of Object.values(entity.fields)) {
switch (field.type) {
// thanks to the type system, `field` has type `IntField`
// after you check that it's type is `FieldType.Int`.
// value will have the type `number | null`.
case FieldType.Int: UseEntityIntValue(field.value); break;
// same goes for any other field type:
case FieldType.Float: UseEntityFloatValue(field.value); break;
case FieldType.String: UseEntityTextValue(field.value); break;
// enum types have an extra field, `ref`, which holds
// a reference to the parent enum.
case FieldType.Enum: UseEntityEnumValue(field.value, field.ref); break;
// array fields have separate entries in `FieldType`:
case FieldType.IntArray:
// field.value type is `number[]`
UseEntityIntArrayValue(field.value); break;
}
}
Grid coordinates
Entity definition identifier
Pivot coordinates (values are from 0 to 1) of the Entity
Pixel coordinates with all offsets applied
Pixel coordinates without applied offsets
Optional Tile used to display this entity (it could either be the default Entity tile, or some tile provided by a field value, like an Enum).
Optional Tileset used to display this entity
Generated using TypeDoc
Entities are generic data that can be placed in your levels, such as the Player start position or Items to pick up.
Entities are collections of custom fields.
Each field has a
typeandvalue.The possible types can be found in FieldType.
Visit https://ldtk.io/docs/general/editor-components/entities/ for more information.