SKLabelNode.color
和SKLabelNode.fontColor
有什么区别?我已经知道如何使用SKLabelNode
,并且我不想要任何说明如何使用SKLabelNode
的答案。任何帮助将不胜感激。
文档解释了它们是什么:
/**
Base color that the text is rendered with (if supported by the font)
*/
open var fontColor: UIColor?
/**
Controls the blending between the rendered text and a color. The valid interval of values is from 0.0 up to and including 1.0. A value above or below that interval is clamped to the minimum (0.0) if below or the maximum (1.0) if above.
*/
open var colorBlendFactor: CGFloat
/**
Color to be blended with the text based on the colorBlendFactor
*/
open var color: UIColor?
下面是一个示例,以帮助更好地了解其工作原理:
let label1 = SKLabelNode(text: "Red")
label1.position = CGPoint(x: 0, y: 50)
label1.fontColor = .red
addChild(label1)
let label2 = SKLabelNode(text: "Red")
label2.color = .red
label2.colorBlendFactor = 1.0
addChild(label2)
let label3 = SKLabelNode(text: "Dull Red")
label3.position = CGPoint(x: 0, y: -50)
label3.color = .red
label3.colorBlendFactor = 0.5
addChild(label3)
let label4 = SKLabelNode(text: "White")
label4.position = CGPoint(x: 0, y: -100)
label4.color = .red
label4.colorBlendFactor = 0.0
addChild(label4)
默认情况下,所有标签都是白色的,这在使用colorBlendFactor时会发挥作用。 label1
和label2
是相同的红色。 label1
为红色,因为它的字体颜色设置为红色。 label2
是红色,因为红色与白色的混合系数为 1.0。当标签的颜色混合因子接近 0 时,它会变得越来越白,如label3
和label4
中看到的那样。