cc.Class({
extends: cc.Component,
properties: {
// foo: {
// default: null, // The default value will be used only when the component attaching
// to a node for the first time
// url: cc.Texture2D, // optional, default is typeof default
// serializable: true, // optional, default is true<a class="attachment" href="/uploads/default/original/3X/f/9/f98d7965b80cf8038f74da1238aaa365bff161c6.zip">NewProject.zip</a> (267.7 KB)
// visible: true, // optional, default is true
// displayName: 'Foo', // optional
// readonly: false, // optional, default is false
// },
// ...
Fish: {
default: null,
type: cc.Prefab
},
times: 0,
},
// use this for initialization
onLoad: function () {
this.init();
},
init: function() {
this.birdArray=[];
let FishNum=200;
var Fish = null;
this.FishPool = new cc.NodePool("bird");
for(var i = 0; i < FishNum; ++i){
Fish = cc.instantiate(this.Fish); // 创建节点
this.FishPool.put(Fish); // 通过 putInPool 接口放入对象池
}
},
createBird: function(){
var Fish=null;
if(this.FishPool.size()>0){
Fish=this.FishPool.get();
}else{
return;
}
Fish.parent=this.node;
Fish.setPosition(cc.p(700,0));
var moveAction = cc.moveTo(10,cc.p(-700,0));
var sequenceAction = cc.sequence(moveAction,cc.callFunc(function(){
this.FishPool.put(Fish);
},this));
Fish.runAction(sequenceAction);
Fish.getComponent("cc.Animation").play("0");
},
// called every frame, uncomment this function to activate update callback
update: function (dt) {
if (this.times % 6 === 0)
this.createBird();
this.node.getChildByName("Label").getComponent("cc.Label").string=this.times;
this.times++;
},
});
上面不断生成了prefab中的动画,但每当添加节点超过2000到3000个时,就会出现卡顿,配置越低的手机,卡的时间越长,有人遇到过吗??NewProject.zip (267.7 KB)