I have created a number of CCSprites using spriteWithFile.
How do I change the image for the sprite during runtime?
I need to change a few sprites images qui
Try using atlassed textures for you game because you are using same sprite that too with many instances
Use
CCSpriteFrameCache, CCSpriteBatchNode
So you can optimize the texture cache with even more different textures atlassed in a single texture. And all are batched in a single node. This reduces the number of draw calls too and increases frame rate.
Try using
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"Characters.plist"];
CCSpriteBatchNode* batch = [CCSpriteBatchNode batchNodeWithFile:@"Characters.png" capacity:10];
[self addChild:batch];
CCSprite* player1 = [CCSprite spriteWithSpriteFrameName:@"Luce.png"];
player1.position = ccp(winSize.width * 0.2, winSize.height * 0.8);
[batch addChild:player1];
and use
CCSprite* player = nil;
CCARRAY_FOREACH(batch.children, player1) {
// some computational code and condition
if (sonecondition) {
[player1 setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"spriteframename.png"]];
}
}
in update or in other parts of code
Use Zwoptex
TexturePacker to create 2D texture atlasses
Hope this helps
Good luck