msqar msqar - 4 months ago 19
iOS Question

Not able to change color of BMGlyphLabel in Swift SpriteKit

According to the BMGlyph library, you can change the label color by doing:

self.label.color = UIColor(...)


The font I created using bmGlyph has a 1px black stroke with a white background.

Using SKACtion.colorizeWithColor() isn't an option since it doesn't work. Already tested it. Is not like any normal SKSpriteNode.

I just wanted to change the label color depending on the user's score.
This is my code:

var color = UIColor.whiteColor()

if self.score > 10 {
color = getUIColor(153, g: 185, b: 152, a: 1)
}else if self.score > 40 {
color = getUIColor(156, g: 151, b: 217, a: 1)
}else if self.score > 60 {
color = getUIColor(127, g: 191, b: 217, a: 1)
}else if self.score > 80 {
color = getUIColor(232, g: 121, b: 198, a: 1)
}else if self.score > 100 {
color = getUIColor(232, g: 74, b: 95, a: 1)
}else if self.score > 120 {
color = getUIColor(125, g: 227, b: 179, a: 1)
}else if self.score > 150 {
color = getUIColor(152, g: 226, b: 90, a: 1)
}else if self.score > 200 {
let redRand = CGFloat(arc4random_uniform(255))
let greenRand = CGFloat(arc4random_uniform(255))
let blueRand = CGFloat(arc4random_uniform(255))
color = getUIColor(redRand, g: greenRand, b: blueRand, a: 1)
}

self.scoreLabel.color = color


Any solution for this? I would like to keep my 1px border font.

Thanks.

Answer

There is a bug with sprite kit that will change the colorBlendFactor when certain things happen (Like having a default alpha of 0 will change it to 0 for some reason) Make sure you explicitly set the value whenever you want to make color alterations.