iosskspritenodesklabelnode

Setting background color for SKLabelNode?


I want to know is there a way to set background color for a SKLabelNode not font color. I'm looking for something like below mentioned code, which is available in ios apps.

     label.backgroundColor = [UIColor redColor];

Solution

  • Try adding the SKLabelNode as a child of a SKSpriteNode.

    SKLabelNode *label = [[SKLabelNode alloc]initWithFontNamed:@"Helvetica"];
    label.position = CGPointMake(0, -label.frame.size.height/2);
    
    SKSpriteNode *background = [SKSpriteNode spriteNodeWithColor:[UIColor redColor] size:CGSizeMake(label.frame.size.width, label.frame.size.height)];
    background.position = CGPointMake(200, 100);
    
    [background addChild:label];
    [self addChild:background];