melonJS
    Preparing search index...

    Function registerTiledObjectClass

    • Register a class constructor as a Tiled object factory. When an object with a matching class or name is found in a Tiled map, an instance of the given constructor will be created with new Constructor(x, y, settings), settings being the TMXObject as read from the map.

      A tile object with no class of its own is matched by its tile's class, as in Tiled: give a tile a class in Tiled's tileset editor, and every object placed from that tile is built by the class registered under that name (an object's own class or name, when registered, still comes first). The tile's custom properties are read with TMXObject#resolvedProperty.

      This is a convenience wrapper around registerTiledObjectFactory. If the same class is registered twice with the same constructor, the call is silently ignored. If a different constructor is registered for the same name, an error is thrown.

      Note: classes registered via pool.register are also automatically registered as Tiled object factories (unless pool.autoRegisterTiled is set to false).

      Type Parameters

      Parameters

      • name: string

        the Tiled class or object name to match

      • Constructor: new (x: number, y: number, settings: S) => Renderable

        class constructor, given the object's position and the object (a TMXObject)

      Returns void

      // register a custom enemy class for use in Tiled maps
      // In Tiled: set the object class to "Enemy" and add custom properties
      registerTiledObjectClass("Enemy", Enemy);
      // the older spelling: `pool.register` registers a Tiled factory as a side
      // effect, and additionally makes the class RECYCLABLE, which this registry
      // alone does not do
      pool.register("CoinEntity", CoinEntity, true);