我的SKLabelNode不会改变颜色

时间:2022-11-21 15:45:58

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.

我的iOS应用程序中有一个SKLabelNode来显示玩家的分数。我想能够改变它的颜色(现在,只是标准的青色)。但我似乎无法弄清楚为什么它没有改变。我有另一个应用程序,我已经使用过这个并没有任何问题。

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];


}

3 个解决方案

#1


31  

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

我相信你想使用pScoreNode.fontColor = [UIColor cyanColor] ;.

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

color属性用于与colorBlendFactor一起进行颜色混合。

#2


10  

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

仅供参考,对于那些在Swift中使用的人:

label.fontColor = UIColor.blackColor()

#3


3  

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

例如,如果你想让你的标签黑色使用;

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

#1


31  

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

我相信你想使用pScoreNode.fontColor = [UIColor cyanColor] ;.

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

color属性用于与colorBlendFactor一起进行颜色混合。

#2


10  

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

仅供参考,对于那些在Swift中使用的人:

label.fontColor = UIColor.blackColor()

#3


3  

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

例如,如果你想让你的标签黑色使用;

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