SKAction.rotate 不是 运行 在 SKCameraNode 上
SKAction.rotate not running on SKCameraNode
所以实际的 SKCameraNode
工作正常,因为我让它跟随另一个节点并且工作正常。但是当我尝试用 SKAction
旋转相机时,它不会旋转。但是,当我尝试设置它的 zRotation
时,它工作正常。我真的不明白为什么。
这里是一些摘录。
import SpriteKit
class Field:SKScene {
let screen = UIScreen.main.bounds
var cam = SKCameraNode()
var ball:SKShapeNode = SKShapeNode()
override func didMove(to view: SKView) {
// ball init and other stuff
scene!.camera = cam
}
func followBall() {
cam.position.x = ball.position.x
cam.position.y = ball.position.y+100
}
override func update(_ currentTime: TimeInterval) {
followBall()
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
let location = touch.location(in: self.cam)
if(location.x < screen.width/2) {
cam.run(SKAction.rotate(toAngle: .pi/8, duration: 0.2))
} else if (location.x > screen.width/2) {
cam.run(SKAction.rotate(toAngle: -.pi/8, duration: 0.2))
}
}
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
cam.run(SKAction.rotate(toAngle: 0, duration: 0.2))
}
}
cam 未添加到场景中 @0x141E 提供了答案。
所以实际的 SKCameraNode
工作正常,因为我让它跟随另一个节点并且工作正常。但是当我尝试用 SKAction
旋转相机时,它不会旋转。但是,当我尝试设置它的 zRotation
时,它工作正常。我真的不明白为什么。
这里是一些摘录。
import SpriteKit
class Field:SKScene {
let screen = UIScreen.main.bounds
var cam = SKCameraNode()
var ball:SKShapeNode = SKShapeNode()
override func didMove(to view: SKView) {
// ball init and other stuff
scene!.camera = cam
}
func followBall() {
cam.position.x = ball.position.x
cam.position.y = ball.position.y+100
}
override func update(_ currentTime: TimeInterval) {
followBall()
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch in touches {
let location = touch.location(in: self.cam)
if(location.x < screen.width/2) {
cam.run(SKAction.rotate(toAngle: .pi/8, duration: 0.2))
} else if (location.x > screen.width/2) {
cam.run(SKAction.rotate(toAngle: -.pi/8, duration: 0.2))
}
}
}
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
cam.run(SKAction.rotate(toAngle: 0, duration: 0.2))
}
}
cam 未添加到场景中 @0x141E 提供了答案。