yegomo
yegomo

Reputation: 297

how can i change all sprites' image in NSMutableArray

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

Answers (1)

Logan
Logan

Reputation: 53142

Try something like this:

for (CCSprite * sprite in _targets) {
    [sprite setTexture:[[CCTextureCache sharedTextureCache] addImage:@"newImg.png"]];
}

Upvotes: 2

Related Questions