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

Source:
pooling.js, line 8

Methods

<static> exists(name) → {Boolean}

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

<static> pull(className) → {Object}

Pull a new instance of the requested object (if added into the object pool)
Parameters:
Name Type Argument Description
className String as used in me.pool.register
arguments... <optional>
arguments to be passed when instantiating/reinitializing the object
Source:
pooling.js, line 83
Returns:
the instance of the requested object
Type
Object
Examples
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
me.game.world.removeChild(enemy);
me.game.world.removeChild(bullet);

<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
Source:
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
Parameters:
Name Type Description
instance Object to be recycled
Source:
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
Parameters:
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
Source:
pooling.js, line 52
Example
// 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);
Copyright © 2011 - 2017, Olivier Biot, Jason Oster, Aaron McLeod
Documentation generated by JSDoc 3.4.0 on 2017-02-28T11:37:41+08:00 using the DocStrap template modified by codename-.