精灵套装游戏xcode中得分的奖励

时间:2014-09-21 05:20:20

标签: ios objective-c sprite-kit

我正在制作一个游戏,我可以轻松地获得sklabelnode的分数,即使我在用户达到25分,50分等时如何获得奖励,但是当我达到50而且> 50即时获得青铜而不是银和黄金等等,我犯了一个错误。

@implementation MyScene {
int _gameScore;
SKNode *_gameLayer;}

-(void)didBeginContact:(SKPhysicsContact *)contact



 SKSpriteNode *coin = nil;
    if (_gameScore >= 25) {

        coin = [SKSpriteNode spriteNodeWithImageNamed:@"bronze"];
    } else if (_gameScore >= 50) {

        coin = [SKSpriteNode spriteNodeWithImageNamed:@"silver"];   
    }else if (_gameScore >= 100) {

        coin = [SKSpriteNode spriteNodeWithImageNamed:@"gold"];   
    }
    else {
        //blank coin
        coin = [SKSpriteNode spriteNodeWithImageNamed:@"noreward"];
    }

    if (coin != nil) {

        coin.position = CGPointMake(self.size.width/2, self.size.height/2 );
        coin.zPosition = 201;
         [coin setSize:CGSizeMake(100, 100)];

        [_gameLayer addChild:coin];
    }

1 个答案:

答案 0 :(得分:3)

你现在拥有它的方式,你会看到你的"青铜"任何时候_gameScore都大于或等于25。由于50100也大于25,并且在检查25之后,您对它们的检查是,您永远不会看"银"或"黄金"

由于您使用>=,您的支票应该从最高到最低:

if (_gameScore >= 100) {

    coin = [SKSpriteNode spriteNodeWithImageNamed:@"gold"];   
} else if (_gameScore >= 50) {

    coin = [SKSpriteNode spriteNodeWithImageNamed:@"silver"];   
} else if (_gameScore >= 25) {

    coin = [SKSpriteNode spriteNodeWithImageNamed:@"bronze"];
} else {
    //blank coin
    coin = [SKSpriteNode spriteNodeWithImageNamed:@"noreward"];
}