SKAame.Not上未运行SKAction.rotate

时间:2018-01-06 01:51:58

标签: ios swift sprite-kit sknode

所以实际的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))
  }
}

1 个答案:

答案 0 :(得分:0)

没有将摄像头添加到场景中,@ 0x141E提供了答案。