Reputation: 297
Please look at following code
thesprite = [CCSprite spriteWithFile:[NSString stringWithFormat:@"%d.png",s]];
thesprite.position = ccp(point.x, point.y);
[self addChild:thesprite];
[_targets addObject:thesprite];//here _targets is NSMutableArray type
I use the code to add ten sprites in _targets, and now I want to update all sprites' images, I use code like following
[thesprite setTexture:[[CCTextureCache sharedTextureCache] addImage:@"newImg.png"]];
but it only changes the last sprite's image, so how can I do?
Upvotes: 0
Views: 36
Reputation: 53142
Try something like this:
for (CCSprite * sprite in _targets) {
[sprite setTexture:[[CCTextureCache sharedTextureCache] addImage:@"newImg.png"]];
}
Upvotes: 2