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

Method pull

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

* Pull a new instance of the requested object (if added into the object pool) * @param {string} name - as used in pool.register * @param {...*} [args] - arguments to be passed when instantiating/reinitializing the object * @returns {object} the instance of the requested object * @exa

(name, ...args)

Source from the content-addressed store, hash-verified

123 * app.world.removeChild(bullet);
124 */
125 pull(name, ...args) {
126 const className = this.objectClass[name];
127 if (className) {
128 const proto = className["class"];
129 const poolArray = className.pool;
130 let obj;
131
132 if (poolArray && (obj = poolArray.pop())) {
133 // poolable object must implement a `onResetEvent` method
134 obj.onResetEvent.apply(obj, args);
135 this.instance_counter--;
136 } else {
137 // create a new instance
138 obj = new (proto.bind.apply(proto, [proto, ...args]))();
139 if (poolArray) {
140 obj.className = name;
141 }
142 }
143 return obj;
144 }
145 throw new Error("Cannot instantiate object of type '" + name + "'");
146 }
147
148 /**
149 * purge the object pool from any inactive object <br>

Callers 14

createSpriteFromNameMethod · 0.80
readImageLayerFunction · 0.80
readMapObjectsMethod · 0.80
factoryFnFunction · 0.80
originalShapeFactoryFunction · 0.80
spawnContrailNodeMethod · 0.80
spawnBulletMethod · 0.80
spawnEnemyBulletMethod · 0.80
updateMethod · 0.80
displayMethod · 0.80

Calls 1

applyMethod · 0.45

Tested by 1

originalShapeFactoryFunction · 0.64