我正在尝试更改数组中的精灵正在显示的图像。这是我正在使用的代码:
((Sprite *)[enemiesArray objectAtIndex:index]).image = baseImage;
我收到错误消息:
error: request for member 'image' in something not a structure or union
我究竟做错了什么?
谢谢阅读。
我正在尝试更改数组中的精灵正在显示的图像。这是我正在使用的代码:
((Sprite *)[enemiesArray objectAtIndex:index]).image = baseImage;
我收到错误消息:
error: request for member 'image' in something not a structure or union
我究竟做错了什么?
谢谢阅读。
我这样做:
Texture2D *texture = [[Texture2D alloc] initWithImage:myUIImage]
[sprite setTexture: texture];
你最好这样做:
在初始化的某个地方:
CCSpriteBatchNode *spritesheet = [CCSpriteBatchNode batchNodeWithFile:@"car_anim.png"];
[self addChild:spritesheet];
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"car_anim.plist"];
在某处行动:
[yourSprite setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:@"car_left.png"]];
*.plist 和 *.png 可以用 Zwoptex 完成。
当您尝试在执行此操作时更改纹理时,其他解决方案可能会破坏您的动画。
我不认为这是做到这一点的方法。而不是你应该调用 init 方法之一:
- (id) initWithCGImage:(CGImageRef)image;
- (id) initWithTexture:(Texture2D*) tex;
- (id) initWithFile:(NSString *) imageFile;
在我的游戏中,我这样做的方式不同,我的对象有一个名为“Zed”的类,我也将它存储在一个数组中。它有一个精灵作为一个字段,如果我想更改图像,我会交换整个精灵并确保我隐藏旧的并显示新的。
尝试使用
[((Sprite *)[enemiesArray objectAtIndex:index]) setImage:baseImage];