[英]How to rotate a Sprite 90 degrees in SpriteKit
我試圖將精靈增加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
的事實,我可以說這可能是因為car.zRotation
的當前值不是0.0而是類似-M_PI_2
。 因此,將其設置為M_PI_2
您會旋轉180度。 設置新值之前,請嘗試打印car.zRotation
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.