Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Entity

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 type and value.

The possible types can be found in FieldType.

Visit https://ldtk.io/docs/general/editor-components/entities/ for more information.

Hierarchy

  • Entity

Index

Constructors

Properties

Accessors

Constructors

constructor

Properties

Readonly fields

fields: Readonly<Record<string, Field>>

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;
    }
}

Private tileset_

tileset_: undefined | Tileset

Readonly world

world: World

Accessors

gridPos

id

  • get id(): string
  • Entity definition identifier

    Returns string

pivot

  • Pivot coordinates (values are from 0 to 1) of the Entity

    Returns Point

pos

relativePos

  • get relativePos(): Point

tile

  • 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).

    Returns null | EntityInstanceTile

tileset

  • get tileset(): undefined | Tileset
  • Optional Tileset used to display this entity

    Returns undefined | Tileset

Generated using TypeDoc