Thursday, 21 July 2016

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.



from Recent Questions - Stack Overflow http://ift.tt/29Q2c7g
via https://ifttt.com/ IFTTT

No comments:

Post a Comment