我试图将旋转添加到一个精灵90度,所以如果我在它上面点击,它会朝那个方向移动90度。像玩蛇游戏一样思考。
在我的触摸Began方法中,我可以让精灵旋转,但它似乎会翻转自己,实际上并没有旋转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
。