22

I have an SKLabelNode in my iOS app to display a player's score. I want to be able to change the color of it (for now, just to a standard cyan color). But I can't seem to figure out why it's not changing. I have another app where I've used this and had no issues at all.

SKLabelNode *pScoreNode;

NSString *playerScoreTracker;

- (SKLabelNode *)playerScoreNode
{
    pScoreNode = [SKLabelNode labelNodeWithFontNamed:@"NEONCLUBMUSIC"];

    playerScoreTracker = [NSString stringWithFormat:@"POWER: %ld",(long)player_score];

    pScoreNode.text = playerScoreTracker;
    pScoreNode.fontSize = 20;
    pScoreNode.position = CGPointMake(CGRectGetMidX(self.frame),inBoundsOffset/3);
    pScoreNode.color = [SKColor cyanColor];

    pScoreNode.name = @"player1ScoreNode";

    return pScoreNode;
}

Then later in the update, I update the string with the updated score on each update.

-(void)update:(CFTimeInterval)currentTime {
    /* Called before each frame is rendered */

    pScoreNode.text = [NSString stringWithFormat:@"POWER: %ld",(long)player_score];


}
Piyush Dubey
  • 2,416
  • 1
  • 24
  • 39
Justgrant2009
  • 603
  • 1
  • 8
  • 18

3 Answers3

36

I believe you want to use pScoreNode.fontColor = [UIColor cyanColor];.

The color property is for color blending in conjunction with colorBlendFactor.

Thompson
  • 1,098
  • 11
  • 25
12

FYI, for those of you doing this in Swift use:

label.fontColor = UIColor.blackColor()
DamongoCoder
  • 431
  • 5
  • 7
3

For example if u want to make your label black use;

label.color = [SKColor blackColor];
label.colorBlendFactor = 1;