Namespace: pool

me. pool

A pool of Object entity
This object is used for 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 entity 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 object 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

pooling.js, line 8


<static> exists(name) → {Boolean}

Check if an object with the provided name is registered
Name Type Description
name String of the registered object
pooling.js, line 183
true if the classname is registered

<static> pull(className) → {Object}

Pull a new instance of the requested object (if added into the object pool)
Name Type Argument Description
className String as used in me.pool.register
arguments... <optional>
arguments to be passed when instantiating/reinitializing the object
pooling.js, line 83
the instance of the requested object
me.pool.register("player", PlayerEntity);
var player = me.pool.pull("player");
me.pool.register("bullet", BulletEntity, true);
me.pool.register("enemy", EnemyEntity, true);
// ...
// when we need to manually create a new bullet:
var 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:
var 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;;

<static> purge()

purge the entity pool from any inactive object
Object pooling must be enabled for this function to work
note: this will trigger the garbage collector
pooling.js, line 145

<static> push(instance)

Push back an object instance into the entity pool
Object pooling for the object class must be enabled, and object must have been instantiated using me.pool#pull, otherwise this function won't work
Name Type Description
instance Object to be recycled
pooling.js, line 162

<static> register(className, class, objectPooling)

register an object to the pool.
Pooling must be set to true if more than one such objects will be created.
(note) If pooling is enabled, you shouldn't instantiate objects with `new`. See examples in me.pool#pull
Name Type Argument Default Description
className String as defined in the Name field of the Object Properties (in Tiled)
class Object corresponding Class to be instantiated
objectPooling Boolean <optional>
false enables object pooling for the specified class - speeds up the game by reusing existing objects
pooling.js, line 52
// add our users defined entities in the entity pool
me.pool.register("playerspawnpoint", PlayerEntity);
me.pool.register("cherryentity", CherryEntity, true);
me.pool.register("heartentity", HeartEntity, true);
me.pool.register("starentity", StarEntity, true);