Register a class for the objects of a level. 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 an object with a matching class or name is found in a level,
an instance of the given constructor will be created with new Constructor(x, y, settings),
settings being the object as the level describes it (a TMXObject
for a Tiled map, an LDtkObjectSettings for an LDtk level).
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 registerObjectFactory.
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).
class constructor, given the object's position and the object as the level describes it
Returns void
Example
// register a custom enemy class for the objects of a level // In Tiled: set the object class to "Enemy" and add custom properties // In LDtk: name the entity "Enemy" and give it fields registerObjectClass("Enemy", Enemy);
Example
// 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);
Register a class for the objects of a level. 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 an object with a matching
classornameis found in a level, an instance of the given constructor will be created withnew Constructor(x, y, settings),settingsbeing the object as the level describes it (a TMXObject for a Tiled map, anLDtkObjectSettingsfor an LDtk level).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 registerObjectFactory. 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).