vendredi 4 septembre 2015

Setting property value within an If statement

How would I set a value for a property within an if statement that can be accessed outside of the scope of the if statement? My attempt:

@interface GamePlayScene ()
@property (nonatomic) PlayerNode *player;
@property (nonatomic) CGPoint playerPosition;
@end

@implementation GamePlayScene
- (void) didMoveToView:(SKView *)view{
     ...
    if (IS_IPHONE_4){
        self.playerPosition = CGPointMake(CGRectGetMidX(self.frame)-210, CGRectGetMidY(self.frame)-100);

    }
    else if (IS_IPHONE_5){
        self.playerPosition = CGPointMake(CGRectGetMidX(self.frame)-230, CGRectGetMidY(self.frame)-100);

    }
    self.player = [PlayerNode playerAtPosition:_playerPosition withImage:@"HeroRun1"];
    [self addChild:self.player];
    ...
}

The playerPosition property does not retain the value set within the if statement.

Aucun commentaire:

Enregistrer un commentaire