CCObjectPool<T>
CCObjectPool
Cocos2DGeneric object pool for CCNode subclasses. Avoids garbage collection pressure by reusing node instances instead of creating and destroying them. Usage: var pool = new CCObjectPool<Bullet>(parentNode, initialSize: 20); var bullet = pool.Get(); // retrieves from pool or creates new pool.Return(bullet); // returns to pool (hides, does not remove from scene)
Inheritance: System.Object
Constructors
CCObjectPool(CCNode, int)
CCObjectPool(CCNode, int)(Cocos2D.CCNode parent, System.Int32 initialSize)Creates a new object pool.
Parameters:
parent (Cocos2D.CCNode) - Optional parent node. When set, new objects are automatically added as children.initialSize (System.Int32) - Number of objects to pre-allocate.Example
Properties
Number of currently active (in-use) objects.
Number of objects available in the pool.
Methods
ForEachActive(Action)
ForEachActive(Action)(System.ActionT action)Executes an action on each active object. Safe to call Return() inside the action.
Parameters:
action (System.ActionT)Example
Get()
T Get()()Retrieves an object from the pool, or creates a new one if the pool is empty. The object is made visible and OnActivate is called if it implements ICCPoolable.
Returns:
TExample
Return(T)
Return(T)(T obj)Returns an object to the pool. The object is hidden (not removed from scene graph) and OnReset is called if it implements ICCPoolable.
Parameters:
obj (T)Example
ReturnAll()
ReturnAll()()Returns all active objects to the pool.
Example