类似在大飞机游戏,接水果游戏等等中。子弹和下落精灵的不断创建是会影响的内开资。机器差点会影响到整个游戏的体验。但是,不用怕,有cc.pool。
var newSpr = cc.Sprite.extend({
id:null,
movefuc:null,
ctor:function(res){
this._super();
this.initWithFile(res);
this.id = res;
return true;
},
reuse:function(res) {
this.initWithFile(res);
this.id = res;
},
unuse:function() {
this.id = null;
this.retain();//if in jsb
}
})
在场景中调用ta:
var target;
if(cc.pool.hasObject(newSpr)){
target = cc.pool.getFromPool(newSpr,res);
}else{
target = new newSpr(res);
}
在最后处理精灵的地方 放入回收池:
cc.