Let your class supportcc.pool
First, you need to use thecc.pool
Implemented in the class to be managedreuse
Andunuse
Methodcc.pool
In the executionputInPool
will be called when the object'sunuse
Method that can be used inunuse
Before entering the Recycle pool,reuse
Is the reinitialization when you want to remove objects from the recycle pool, and you can initialize the object to a state that is re-usable.
var MySprite = cc. Sprite.extend ({_hp:0, _sp:0, _mp:0, Ctor:function (F1, F2, F3) {This._super (F1, F2, F3); This.initdata (F1, F2, F3); }, Initdata:function (F1, F2, F3) {this._hp = F1; THIS._MP = F2; THIS._SP = F3; }, Unuse:function () {this._hp = 0; THIS._MP = 0; this._sp = 0; This.retain ();//if in JSB this.setvisible (false); This.removefromparent (TRUE); }, Reuse:function (F1, F2, F3) {This.initdata (F1, F2, F3); This.setvisible (TRUE); }}); Mysprite.create = function (f1, F2, F3) {return new MySprite (F1, F2, f3)}mysprite.recreate = function (f1, F2, F3) { var pool = Cc.pool; if (Pool.hasobject (MySprite)) return Pool.getfrompool (MySprite, F1, F2, F3); Return Mysprite.create (F1, F2, F3);}
Put into the recycling pool
cc.pool.putInPool(object);
Call this method to invoke the object's unuse
method and put the object into the recycle pool.
Reclaim objects from the Recycle pool
var object = cc.pool.getFromPool("MySprite", args);
When you need to fetch an object from the Recycle pool, you can call the class of the getFromPool
incoming object and pass in the initialization parameters that need to be passed in, which will be passed into the reuse method, and the cc.pool
reuse method will be called automatically.
Determine if an object is available in the Recycle pool
var exist = Cc.pool.hasObject (" MySprite ");
This method is used to find out if there is
Delete an object in the Recycle pool
cc.pool.removeobject (object);
The object you want to delete is passed in, and the object will be deleted from the Recycle pool.
emptying the Recycle pool
cc.pool.drainallpools ();
When you need to clear all the objects in the recycle pool, such as completing the game to go to another page, the recyclable objects in the old page are no longer useful, to avoid unnecessary memory consumption, you can use drainallpools
deletes all recyclable objects.