Pool Class
A fixed-length object pool designed for general type.
The implementation of this object pool is very simple,
it can helps you to improve your game performance for objects which need frequent release and recreate operations
Index
Properties
countNumberThe current number of available objects, the default is 0, it will gradually increase with the recycle of the object, the maximum will not exceed the size specified when the constructor is called.
Methods
constructorConstructor for creating an object pool for the specific object type. You can pass a callback argument for process the cleanup logic when the object is recycled.getGet and initialize an object from pool. This method defaults to null and requires the user to implement it._getGet an object from pool, if no available object in the pool, null will be returned.putPut an object into the pool.resizeResize the pool.
Details
Properties
count
The current number of available objects, the default is 0, it will gradually increase with the recycle of the object, the maximum will not exceed the size specified when the constructor is called.
| meta | description |
|---|---|
| Type | Number |
| Defined in | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/js.js:894 |
Methods
constructor
Constructor for creating an object pool for the specific object type. You can pass a callback argument for process the cleanup logic when the object is recycled.
| meta | description |
|---|---|
| Defined in | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/js.js:859 |
Parameters
cleanupFuncFunction the callback method used to process the cleanup logic when the object is recycled.objObject
sizeNumber initializes the length of the array
get
Get and initialize an object from pool. This method defaults to null and requires the user to implement it.
| meta | description |
|---|---|
| Returns | Object |
| Defined in | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/js.js:884 |
Parameters
paramsAny parameters to used to initialize the object
_get
Get an object from pool, if no available object in the pool, null will be returned.
| meta | description |
|---|---|
| Returns | Object | Null |
| Defined in | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/js.js:904 |
put
Put an object into the pool.
| meta | description |
|---|---|
| Defined in | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/js.js:922 |
resize
Resize the pool.
| meta | description |
|---|---|
| Defined in | https:/github.com/cocos-creator/engine/blob/master/cocos2d/core/platform/js.js:938 |