/** * Set a callback to be invoked whenever pool.register() is called. * @param {Function} callback - function(className, classObj, poolInstance) called on each registration * @ignore */ export function setPoolRegisterCallback(callback: Function): void; export default pool; /** * a default global ObjectPool instance * @namespace pool * @see ObjectPool * @example * // register our bullet object into the object pool * pool.register("bullet", BulletEntity, true); * // ... * // when we need to manually create a new bullet: * let bullet = pool.pull("bullet", x, y, direction, velocity); * // ... * // when we want to destroy existing object, the remove * // function will ensure the object can then be reallocated later * game.world.removeChild(bullet); */ declare const pool: ObjectPool; /** * Object pooling - a technique that might speed up your game if used properly.
* If some of your classes will be instantiated and removed a lot at a time, it is a * good idea to add the class to this object pool. A separate pool for that class * will be created, which will reuse objects of the class. That way they won't be instantiated * each time you need a new one (slowing your game), but stored into that pool and taking one * already instantiated when you need it.

* This technique is also used by the engine to instantiate objects defined in the map, * which means, that on level loading the engine will try to instantiate every object * found in the map, based on the user defined name in each Object Properties
*
* @see {@link pool} the default global instance of ObjectPool */ declare class ObjectPool { objectClass: {}; instance_counter: number; /** * When enabled, classes registered via {@link pool.register} are also * automatically registered as Tiled object factories, so that objects * placed in a Tiled map with a matching class or name will be * instantiated using the registered constructor. * Set to `false` to disable this behavior (e.g. for classes that should * only be used programmatically and not from Tiled maps). * @type {boolean} * @default true * @example * // disable auto-registration for a specific class * pool.autoRegisterTiled = false; * pool.register("InternalHelper", HelperClass); * pool.autoRegisterTiled = true; // re-enable for subsequent registrations */ autoRegisterTiled: boolean; /** * 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, * meaning objects placed in a Tiled map with a matching class or name will be * instantiated using the registered constructor. For more control, use * {@link registerTiledObjectClass} or {@link registerTiledObjectFactory} instead. * @param {string} className - as defined in the Name field of the Object Properties (in Tiled) * @param {object} classObj - corresponding Class to be instantiated * @param {boolean} [recycling=false] - enables object recycling for the specified class * @example * // implement CherryEntity * class Cherry extends Sprite { * onResetEvent() { * // reset object mutable properties * this.lifeBar = 100; * } * }; * // add our users defined entities in the object pool and enable object recycling * // this also registers "cherrysprite" as a Tiled object factory, so any object * // with class or name "cherrysprite" in a Tiled map will create a Cherry instance * me.pool.register("cherrysprite", Cherry, true); */ register(className: string, classObj: object, recycling?: boolean): void; /** * Pull a new instance of the requested object (if added into the object pool) * @param {string} name - as used in {@link pool.register} * @param {...*} [args] - arguments to be passed when instantiating/reinitializing the object * @returns {object} the instance of the requested object * @example * me.pool.register("bullet", BulletEntity, true); * me.pool.register("enemy", EnemyEntity, true); * // ... * // when we need to manually create a new bullet: * let bullet = me.pool.pull("bullet", x, y, direction); * // ... * // params aren't a fixed number * // when we need new enemy we can add more params, that the object construct requires: * let enemy = me.pool.pull("enemy", x, y, direction, speed, power, life); * // ... * // when we want to destroy existing object, the remove * // function will ensure the object can then be reallocated later * app.world.removeChild(enemy); * app.world.removeChild(bullet); */ pull(name: string, ...args?: any[]): object; /** * purge the object pool from any inactive object
* Object pooling must be enabled for this function to work
* note: this will trigger the garbage collector */ purge(): void; /** * Push back an object instance into the object pool
* Object pooling for the object class must be enabled, * and object must have been instantiated using {@link pull}, * otherwise this function won't work * @throws will throw an error if the object cannot be recycled * @param {object} obj - instance to be recycled * @param {boolean} [throwOnError=true] - throw an exception if the object cannot be recycled * @returns {boolean} true if the object was successfully recycled in the object pool */ push(obj: object, throwOnError?: boolean): boolean; /** * Check if an object with the provided name is registered * @param {string} name - of the registered object class * @returns {boolean} true if the classname is registered */ exists(name: string): boolean; /** * Check if an object is poolable * (was properly registered with the recycling feature enable) * @see register * @param {object} obj - object to be checked * @returns {boolean} true if the object is poolable * @example * if (!me.pool.poolable(myCherryEntity)) { * // object was not properly registered * } */ poolable(obj: object): boolean; /** * returns the amount of object instance currently in the pool * @returns {number} amount of object instance */ getInstanceCount(): number; } //# sourceMappingURL=legacy_pool.d.ts.map