Hello.
I’m pleasure to post the first topic in this forum.
I’m developing the game by using cocoscreator 1.9.2.
I found the fps low issue when I had added many sprites in node.
The code is the following
Blockquote
cc.Class({
extends: cc.Component,
properties: {
spAtlas:{
default:null,
type:cc.SpriteAtlas
}
},
onLoad () {
this.d_node = 1000;
this.pos_out = cc.p(100000, 100000);
this.array_body = [];
this.body_time = 0;
},
start () {
var p_node;
var comp;
var i;
for (i = 0; i < this.d_node; i++) {
p_node = new cc.Node();
comp = p_node.addComponent(cc.Sprite);
comp.spriteFrame = this.spAtlas.getSpriteFrame('node');
p_node.setScale(1, 1);
p_node.position = this.pos_out;
p_node.rotation = 0;
this.node.addChild(p_node, 2, 1);
this.array_body.push(p_node);
}
},
update (dt) {
this.body_time ++;
this.redraw();
},
redraw() {
var p_node;
var i;
var scale;
var x, y;
for (i = 0; i < this.d_node; i++) {
p_node = this.array_body[i];
p_node.position = this.pos_out;
if (this.body_time > 20) {
scale = this.randomInt(0.4, 1);
p_node.setScale(scale);
x = randomInt(-500, 500);
y = randomInt(-500, 500);
p_node.position = cc.p(x,y);
}
}
},
randomInt: function(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
},
}
Blockquote
The fps will be 30 when this code is running.
I hope to use CCSpriteBatchNode or CCSpriteFrameCache like as cocos2d-x.
Is anyone to help me.
Best Regards