如果项目收集精灵工具包,如何添加到弹药

时间:2014-03-19 06:57:41

标签: sprite-kit

我有一个游戏,那个人跑来跑去收集东西。所以我希望得分管理员在收集项目时更新并增加,如果他使用该项目则减少。例如,生活项目。所以这里是我到目前为止标签的代码,但它与文本分数不整数。有任何想法吗?感谢

   - (void)setupUI
          {
          int barHeight = 45;
          CGSize backgroundSize = CGSizeMake(self.size.width, barHeight);
          SKColor *backgroundColor = [SKColor colorWithWhite:10 alpha:50];
          SKSpriteNode *hudBarBackground = [SKSpriteNode spriteNodeWithColor:backgroundColor size:backgroundSize];
          hudBarBackground.position = CGPointMake(0, self.size.height - barHeight);
          hudBarBackground.anchorPoint = CGPointZero;
          [_hudLayerNode addChild:hudBarBackground];
          // 1
          SKLabelNode *scoreLabel = [SKLabelNode labelNodeWithFontNamed:@"AvenirNextCondensed-HeavyItalic"];
          // 2
          scoreLabel.fontSize = 20.0;
          scoreLabel.text = @"Score: 0";
          scoreLabel.name = @"scoreLabel";
          scoreLabel.fontColor = [SKColor orangeColor];
          // 3
          scoreLabel.verticalAlignmentMode = SKLabelVerticalAlignmentModeCenter;
          // 4
          scoreLabel.position = CGPointMake(self.size.width - self.size.width / 4, self.size.height - scoreLabel.frame.size.height + 3);
          // 5

          [_hudLayerNode addChild:scoreLabel];
          _scoreFlashAction = [SKAction sequence: @[[SKAction scaleTo:1.5 duration:0.1],      
          [SKAction scaleTo:1.0 duration:0.1]]];
          [scoreLabel runAction: [SKAction repeatAction:_scoreFlashAction count:10]];
          }

1 个答案:

答案 0 :(得分:0)

double score; //property
-(void)setupUI {
    //...
    SKAction *tempAction = [SKAction runBlock:^{
        scoreLabel.text = [NSString stringWithFormat:@"Score: 3.0f", self.score];
    }];
    SKAction *waitAction = [SKAction waitForDuration:0.2];
    [scoreLabel runAction:[SKAction repeatActionForever:[SKAction sequence:@[tempAction,waitAction]]]];
    //...
}