baihu
baihu

Reputation: 461

Unexpected identifier error - SpriteKit

I am very new to SpriteKit and objective c so I am playing about and I have reached an error message which I have been unable to fix. I get an unexpected identifier message and I am unsure why. I am doing it this way as I want to understand the way functions work in objective-c. I was wondering if someone could help me in the right direction as to this issue.

The code is this.

@implementation HMGameScene

-(id)initWithSize:(CGSize)size {
    if (self = [super initWithSize:size]) {
        SKSpriteNode *lvl1_bg_image = [HMGameScene set_lvl1_bg];
        [self addChild:lvl1_bg_image];
    }
    return self;
}

+(SKSpriteNode*) set_lvl1_bg {
    SKSpriteNode *lvl1_bg_image = [SKSpriteNode spriteNodeWithImageNamed:@"lvl1bg"];
    return [SKSpriteNode *lvl1_bg_image]; // The error is here
}
@end

Thanks

Upvotes: 0

Views: 95

Answers (1)

Phillip Mills
Phillip Mills

Reputation: 31016

All you need is return lvl1_bg_image;. The square bracket syntax is [receiver message] where the receiver is some object (or class) and the message resolves to some method you want invoked. Since you're not trying to call any SKSpriteNode method and *lvl1_bg_image is a pointer, not a message, the compiler doesn't like the syntax.

Upvotes: 2

Related Questions