Register a function building the objects of a level, for a class or a name.
The registry is the same whatever the level was made with: an object of a
Tiled or a Sprite Fusion map, an entity of an LDtk level.
When a level is loaded, objects are matched to factories using the following
priority: object class → object name → structural type ("text", "tile", "shape").
Built-in structural types are: "text", "tile", "shape".
Custom types are matched against the object's Tiled class or name property.
A tile object with no class of its own is matched by its tile's class.
For simple cases where you just want to map a Tiled class to a constructor,
use registerObjectClass instead.
the object type key (built-in type or Tiled class/name)
factory function, given the object as the level describes it (a TMXObject for a Tiled map) and the map it is read from (the level, for an LDtk one)
// register a custom factory for "Spine" objects in Tiled
// (set the object class to "Spine" in Tiled, and add atlasFile/jsonFile custom properties)
registerObjectFactory("Spine", (settings, map) => {
const obj = new Spine(settings.x, settings.y, settings);
obj.pos.z = settings.z;
return obj;
});
The older name of registerObjectFactory: the same function, kept so that existing games and plugins go on working.
Deprecated
since 20.18.0, use registerObjectFactory
Template: S
Param: type
the class or name the level gives the object
Param: factory
given the object's description and the map it is read from