Cocos2d. Use 1 sprites many times for create a random map?

549 views Asked by At

I generate the length of the maps randomly, adding to the main Sprites chaild sprite, as a result of my fall FPS and everything slows down.

Can I use a sprite many times it does not allocate memory.? Code looks like this:

int z  = rand % 10; 
for (int i = 0; i < z; i++)
{

  CCSprite  *waterLenght = [CCSprite spriteWithFile:@"water.png"];
    waterLenght.position = ccp([waterStart boundingBox].size.width +20*i, 0);

    [waterStart addChild:waterLenght];

}
[self addChild:waterStart];
1

There are 1 answers

0
CodeSmile On

Yes. If you create multiple instances of CCSprite using the same image, the image will be loaded into memory as a texture only once.