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
count
Number
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.
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.get
Get and initialize an object from pool. This method defaults to null and requires the user to implement it._get
Get an object from pool, if no available object in the pool, null will be returned.put
Put an object into the pool.resize
Resize 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
cleanupFunc
Function the callback method used to process the cleanup logic when the object is recycled.obj
Object
size
Number 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
params
Any 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 |