Skip to content

Instantly share code, notes, and snippets.

Created January 11, 2017 21:28
Show Gist options
  • Save anonymous/4ea86cf6a32bdd79376cc2a4f4d5a151 to your computer and use it in GitHub Desktop.
Save anonymous/4ea86cf6a32bdd79376cc2a4f4d5a151 to your computer and use it in GitHub Desktop.
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