请查看以下代码
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
我使用代码在_targets中添加十个精灵,现在我想更新所有精灵的图像,我使用如下代码
[thesprite setTexture:[[CCTextureCache sharedTextureCache] addImage:@"newImg.png"]];
但它只会改变最后一个精灵的图像,所以我该怎么办?
答案 0 :(得分:2)
尝试这样的事情:
for (CCSprite * sprite in _targets) {
[sprite setTexture:[[CCTextureCache sharedTextureCache] addImage:@"newImg.png"]];
}