melonJS
    Preparing search index...

    Interface TMXObject

    An object of a Tiled map, as read from the map. It is the settings that a class registered with registerTiledObjectClass receives (and that a factory registered with registerTiledObjectFactory is given), before the object is turned into a renderable.

    The object's own custom properties are set on it by name. TMXObject#resolvedProperties and TMXObject#resolvedProperty also include those a tile object inherits from its tile, as Tiled shows them. A tile object with no class of its own is matched by its tile's class.

    In TypeScript, declare the custom properties a class reads by extending this type.

    import { registerTiledObjectClass, Sprite, type TMXObject } from "melonjs";

    // the custom properties the class reads, as set on the object in Tiled
    interface ChestSettings extends TMXObject {
    locked?: boolean;
    }

    class Chest extends Sprite {
    locked: boolean;
    gold: number;
    constructor(x: number, y: number, settings: ChestSettings) {
    super(x, y, { image: "chest" });
    this.locked = settings.locked ?? false;
    // set on the object, or else on the chest tile in the tileset
    this.gold = settings.resolvedProperty("gold") ?? 10;
    }
    }
    // in Tiled, give the chest tile the class "Chest": every chest placed
    // in the map is then built by this class
    registerTiledObjectClass("Chest", Chest);
    interface TMXObject {
        class: string;
        frameheight: number | undefined;
        framewidth: number | undefined;
        gid: number | null;
        height: number;
        id: number;
        isCapsule: boolean;
        isEllipse: boolean;
        isPoint: boolean;
        isPolygon: boolean;
        isPolyLine: boolean;
        name: string;
        opacity: number;
        orientation: string;
        points: object[];
        rotation: number;
        shapes: object[];
        shapeType: string;
        text: object;
        tile: Tile | undefined;
        tintcolor: string;
        type: string;
        visible: boolean;
        width: number;
        x: number;
        y: number;
        z: number;
        resolvedProperties(): {};
        resolvedProperty(name: string): any;
    }
    Index
    class: string

    the object class

    frameheight: number | undefined

    height of the object's tile in its tileset image, for a tile object from a tileset image (undefined otherwise)

    framewidth: number | undefined

    width of the object's tile in its tileset image, for a tile object from a tileset image (undefined otherwise)

    gid: number | null

    object gid value when defined the object is a tiled object

    height: number

    object height

    id: number

    object unique identifier per level (Tiled 0.11.x+)

    isCapsule: boolean
    isEllipse: boolean
    isPoint: boolean
    isPolygon: boolean
    isPolyLine: boolean
    name: string

    object name

    opacity: number

    the object opacity (0-1), defaults to 1 (since Tiled 1.12)

    orientation: string

    object orientation (orthogonal or isometric)

    points: object[]

    point list in JSON format

    rotation: number

    The rotation of the object in radians clockwise (defaults to 0)

    shapes: object[]

    the collision shapes defined for this object

    shapeType: string

    the detected shape type

    text: object

    object text

    tile: Tile | undefined

    the tile of a tile object (one with a gid), undefined otherwise

    tintcolor: string

    tint color

    type: string

    object type

    visible: boolean

    whether the object is visible, defaults to true

    width: number

    object width

    x: number

    object x position

    y: number

    object y position

    z: number

    object z order

    • Return the object's custom properties, including those it inherits from its tile (for a tile object), as Tiled resolves them: a property the object sets itself wins over its tile's. Each call returns a new object; the values themselves are not copied.

      Returns {}

      the resolved custom properties

      // a door tile has a "facing" property in the tileset: every door
      // object placed from it has it, unless the object sets its own
      const { facing = "N" } = settings.resolvedProperties();
    • Return the value of one custom property of the object, or else of its tile (for a tile object), as Tiled resolves it.

      Parameters

      • name: string

        name of the custom property

      Returns any

      the property's value, or undefined if neither the object nor its tile sets it

      const opens = settings.resolvedProperty("opens");