我正在尝试将 sprite 旋转 90 度,所以如果我在它上面点击,它会移动 90 度并面向那个方向。像蛇游戏一样思考。
在我的 touchesBegan 方法中,我可以让 Sprite 旋转,但它似乎会自行翻转,而不是实际旋转 90 度,更像是 180 度。
关于为什么以及如何让它指向正确方向的任何想法。
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
let touch = touches.first as UITouch!
let touchLocation = touch.locationInNode(self)
sceneTouched(touchLocation)
if (car.position.x > touchLocation.x) {
car.zRotation = CGFloat(M_PI_2)
} else {
car.zRotation = CGFloat(-M_PI_2)
}
}
最佳答案
基于您的代码对我有用的事实,我会说这可能是因为 car.zRotation
的当前值不是 0.0 而是类似于 -M_PI_2
。因此,当您将其设置为 M_PI_2
时,您会旋转 180 度。在设置新值之前尝试打印 car.zRotation
。
关于ios - 如何在 SpriteKit 中将 Sprite 旋转 90 度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34330065/