我正在玩 SpriteKit,对可能是一个非常愚蠢的错误感到目瞪口呆。我正在扩展一个 SKSpriteNode,Fish,声明如下:
@interface Fish : SKSpriteNode
@property BOOL direction;
@property FishSize fishSize;
+ (id) spriteNodeWithImageNamed : (NSString *) name;
- (id) initWithImageNamed :(NSString *)name;
- (void) setSize:(FishSize)s;
@end
我这样重写 spriteNodeWithImageNamed 类方法:
+ (id) spriteNodeWithImageNamed : (NSString *) name
{
Fish * f = [super spriteNodeWithImageNamed : name];
f.direction = right;
f.fishSize = SmallSize;
return f;
}
这是错误的,因为精灵没有被加载。另一方面,如果我只是在常规 SKSpriteNode 上调用 spriteNodeWithImageNamed 方法,它就可以正常工作:
//this gets initialized to the proper size
SKSpriteNode * node = [SKSpriteNode spriteNodeWithImageNamed:picName];
// this is initialized to size (0,0)
Fish * fish = [Fish spriteNodeWithImageNamed:picName];
我究竟做错了什么?