Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sprite kit- Cannot change the colour of text (always white)

I am writing a 2d game in sprite kit and I am creating the menu screen. Everything is ok so far apart from the fact that the text always appears white, whatever values of red, green, blue etc that I enter into the code. This is the code that I am using to create the background for the menu:

-(id)initWithSize:(CGSize)size
{
if (self = [super initWithSize:size]) {

    NSLog(@"Size: %@", NSStringFromCGSize(size));
    [self setBackgroundColor:[SKColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.0]];

    self.writing = [SKLabelNode labelNodeWithFontNamed:@"Thonburi Bold"];
    self.writing.text = @"MAIN MENU";
    self.writing.fontSize = 42;
    self.writing.color = [SKColor colorWithRed:0.1 green:0.1 blue:0.1 alpha:1.0];
    self.writing.position = CGPointMake(130, 270);
    [self addChild:self.writing];
}
return  self;

}

I have other code in the project and I checked that none of it is anything to do with the colour of the text on this screen.

(I am new to programming so this might be a fairly obvious mistake)

Thanks in advance!

like image 925
OLZ1 Avatar asked Dec 25 '22 19:12

OLZ1


1 Answers

The color property is the blend color. You want to use fontColor to change the text's color.

label.fontColor = [SKColor colorWithRed:0.1 green:1 blue:0.1 alpha:1.0];

You could also use color and set colorBlendFactor to 1. Though this might be slower depending on how it's handled internally.

like image 97
LearnCocos2D Avatar answered Feb 25 '23 02:02

LearnCocos2D