我需要一种在 nsmutable 数组中将图像纹理从一个索引切换到另一个索引的方法。
balloonTextures = [NSMutableArray array];
// Add each of the balloon textures into the balloon textures array
[balloonTextures addObject:[SPTexture textureWithContentsOfFile:@"greentutorial.png"]];
[balloonTextures addObject:[SPTexture textureWithContentsOfFile:@"redtutorial.png"]];
SPImage *image = [SPImage imageWithTexture:[balloonTextures objectAtIndex:0]];
image.x = 0;
image.y = 10 ;
[playFieldSprite addChild:image];
[image addEventListener:@selector(onTouchBalloon:) atObject:self forType:SP_EVENT_TYPE_TOUCH];
如您所见,我有一个 NSMutableArray,其中包含图像纹理 greentutorial。现在我想用这种在 20 秒内调用的方法用红色纹理(红色教程)切换它。
-(void)changeColor{
image = [SPImage imageWithTexture:[balloonTextures objectAtIndex:1]];
}
但是,它根本不起作用。我知道图像正在被调用,因为如果我在方法中添加下面的代码并且它可以工作。
image.x = 300;