Created
January 11, 2017 21:28
-
-
Save anonymous/4ea86cf6a32bdd79376cc2a4f4d5a151 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func textToTexture(text: String, | |
color: SKColor = SKColor.black, | |
bordered: Bool = true, | |
borderColor: SKColor = SKColor.yellow) -> SKTexture { | |
let returnNode = SKNode() | |
let tempLabel = SKLabelNode(text: text) | |
tempLabel.fontColor = color | |
tempLabel.verticalAlignmentMode = .center | |
if bordered { | |
let tempBox = SKShapeNode(rectOf: tempLabel.frame.size) | |
tempBox.strokeColor = borderColor | |
tempLabel.setScale(0.9) // To make it fit inside borcer. | |
tempBox.addChild(tempLabel) | |
returnNode.addChild(tempBox) | |
} else { returnNode.addChild(tempLabel) } | |
if let view = g.view { | |
return view.texture(from: returnNode)! | |
} else { fatalError("ttt: view not found") } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment