This is pretty easy with a shader. Add a text file to your project called "TheShader.fsh":
void main() { float yPos = gl_FragCoord.y - labelBase; float gradient = yPos / u_sprite_size.y;
Now create a SKEffectNode in SKScene, set its shader to "TheShader" and add your label as a child of the node effect. The label will be drawn using a vertical gradient from the fontColor label from below to white from above.
override func didMoveToView(view: SKView) { makeGradientLabel("318 nodes 60.0 fps", labelPosition: CGPoint(x: CGRectGetMidX(frame), y: CGRectGetMidY(frame))) } func makeGradientLabel(labelText: String, labelPosition: CGPoint) { let myShader = SKShader(fileNamed: "TheShader") let labelBase = SKUniform(name: "labelBase", float: Float(labelPosition.y)) myShader.addUniform(labelBase) let effectNode = SKEffectNode() effectNode.shader = myShader effectNode.shouldEnableEffects = true addChild(effectNode) let theLabel = SKLabelNode(fontNamed: "Courier") theLabel.fontSize = 36 theLabel.fontColor = SKColor.blueColor() theLabel.text = labelText theLabel.position = labelPosition effectNode.addChild(theLabel) }
If you move the label, you will need to update the labelBase uniform so that the shader knows where it is:
labelBase.floatValue = Float(theLabel.position.y)
source share