更新时间:2023-11-19 15:46:28
我不认为这是做到这一点的方法。
而不是你应该调用一个init方法:
- (id)initWithCGImage:(CGImageRef)image;
- (id)initWithTexture:(Texture2D *)tex;
- (id)initWithFile:(NSString *)imageFile;
在我的游戏中,我做了不同的,我有一个类为我的对象称为'Zed',我也存储在一个数组。它有一个精灵作为一个字段,如果我想改变图像,我交换整个精灵,并确保我隐藏旧的,显示新的。
I'm trying to change the image that a sprite from an array is displaying. Here is the code I'm using:
((Sprite *)[enemiesArray objectAtIndex:index]).image = baseImage;
I get the error message:
error: request for member 'image' in something not a structure or union
What am I doing wrong?
Thanks for reading.
I don't think that this is the way to do this. Rather than that you should call one of the init methods:
- (id) initWithCGImage:(CGImageRef)image;
- (id) initWithTexture:(Texture2D*) tex;
- (id) initWithFile:(NSString *) imageFile;
In my game i do this differently, i have a class for my object called 'Zed' which i also store in an array. It has a sprite as a field and if i want to change the image i swap the whole sprite and make sure i hide the old and show the new one.