Tuesday, 6 August 2013

Fastest way to do something with a group of sprites in cocos2d

Fastest way to do something with a group of sprites in cocos2d

I wanna to zoom a group of about 10 sprites at the same time. The sprites
are different sprite layers with transparent background.
I'm trying to preattach all the sprite at first to the layer and store the
reference in an array. After that as I click the button I do this: Sorry
this is Javascript but in Objective-C it's almost the same.
attr.zoomAllVisibleSprites = function() {
for (var i = 0; i < this.SpriteArray.length; i++) {
if (this.SpriteArray[i].isVisible()) {
this.SpriteArray[i].setAnchorPoint(cc.PointMake(0.5,0.5));
this.SpriteArray[i].setScale(2, 2);
}
}
}
The execution of this little snippet requires on my Android phone about
2-3 seconds which is too much for my game. Is there a way to do it faster,
optimize this code. Maybe group in a different way the sprites could help
?

No comments:

Post a Comment