SKLabelNode without transparent background

故事扮演 提交于 2019-12-10 23:28:25

问题


Hi I'm using a custom font on a SKLabelNode.

I'm able to set the font colour but ok, but the inner parts of the text, are transparent.

Is there a way i can set this colour to white for example?

my code so far

    scoreLabel.fontColor = [SKColor colorWithRed:0.0 green:0 blue:0.0 alpha:1.0];


回答1:


The easiest way I found is to combine an SKSpriteNode and a SKLabelNode. You simply add the SKLabelNode as a child to the SKSpriteNode.

    SKLabelNode *label = [[SKLabelNode alloc]initWithFontNamed:@"Courier"];
    label.text = @"blah";
    label.fontColor = [UIColor blueColor];

    SKSpriteNode *background = [SKSpriteNode spriteNodeWithColor:[UIColor whiteColor] size:CGSizeMake(label.frame.size.width, label.frame.size.height)];
    background.position = CGPointMake(200, 100);
    [background addChild:label];
    label.position = CGPointMake(0, -label.frame.size.height/2);

    [self addChild:background];

The result looks like this...



来源:https://stackoverflow.com/questions/23252899/sklabelnode-without-transparent-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!