How to wrap text around a circle in a sprite set / Swift

I am making a game with SpriteKit / Swift and I want to influence the menu scene where I bend a line around a circle. The next picture is almost what I want to accomplish. http://www.heathrowe.com/tuts/typeonaapathimages/4.gif

+4
source share
1 answer

The following code wraps the characters in a line around the top half of the circle, creating a node label for each symbol in the line, setting the label position to the appropriate location on the circle, and then rotating each node label so that it touches the circle in that position.

class GameScene:SKScene { override func didMove(to view:SKView) { let radius = CGFloat(50.0) let circleCenter = CGPoint.zero let string = "Your Text Here" let count = string.lengthOfBytes(using: String.Encoding.utf8) let angleIncr = CGFloat.pi/(CGFloat(count)-1) var angle = CGFloat.pi // Loop over the characters in the string for (_, character) in string.characters.enumerated() { // Calculate the position of each character let x = cos(angle) * radius + circleCenter.x let y = sin(angle) * radius + circleCenter.y let label = SKLabelNode(fontNamed: "Arial") label.text = "\(character)" label.position = CGPoint(x: x, y: y) // Determine how much to rotate each character label.zRotation = angle - CGFloat.pi / 2 label.fontSize = 30 addChild(label) angle -= angleIncr } } } 

enter image description here

+10
source