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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With