MCPcopy Create free account
hub / github.com/melonjs/melonJS / register

Method register

packages/melonjs/src/system/legacy_pool.js:78–102  ·  view source on GitHub ↗

* Register an object to the pool. * Pooling must be set to true if more than one such objects will be created. * (Note: for an object to be poolable, it must implement an `onResetEvent` method) * Registered classes are also automatically available as Tiled object factories,

(className, classObj, recycling = false)

Source from the content-addressed store, hash-verified

76 * me.pool.register("cherrysprite", Cherry, true);
77 */
78 register(className, classObj, recycling = false) {
79 if (typeof classObj !== "undefined") {
80 const entry = {
81 class: classObj,
82 pool: recycling ? [] : undefined,
83 };
84 this.objectClass[className] = entry;
85 // also register with "me." prefix for backward compatibility
86 if (!className.startsWith("me.")) {
87 this.objectClass["me." + className] = entry;
88 }
89 // also register as a Tiled object factory
90 if (this.autoRegisterTiled && typeof onRegisterCallback === "function") {
91 onRegisterCallback(className, classObj, this);
92 // also register with "me." prefix for backward compatibility
93 if (!className.startsWith("me.")) {
94 onRegisterCallback("me." + className, classObj, this);
95 }
96 }
97 } else {
98 throw new Error(
99 "Cannot register object '" + className + "', invalid class",
100 );
101 }
102 }
103
104 /**
105 * Pull a new instance of the requested object (if added into the object pool)

Callers 15

bootFunction · 0.80
plugin.spec.jsFile · 0.80
rectangle.spec.tsFile · 0.80
tmxtilemap.spec.jsFile · 0.80
roundrect.spec.tsFile · 0.80
createGameFunction · 0.80
createGameFunction · 0.80
createGameFunction · 0.80
registerPoolsMethod · 0.80
createGameFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected