Sam*_*iva 4 ios sprite-kit swift
我正在使用SpriteKit/Swift制作一个游戏,我希望对菜单场景产生影响,我会围绕一个圆圈弯曲一个字符串.以下图片几乎就是我想要完成的. http://www.heathrowe.com/tuts/typeonaapathimages/4.gif
0x1*_*41E 10
通过为字符串中的每个字符创建标签节点,将标签的位置设置为圆上的适当位置,然后旋转每个标签节点,以下代码将字符包裹在圆圈的上半部分周围的字符串中它与该位置的圆相切.
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
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1203 次 |
| 最近记录: |