2015-12-17 58 views
1

Im試圖將旋轉添加到Sprite 90度,所以如果我點擊它上面,它將向90度方向移動一個面向該方向的面。像蛇遊戲一樣思考。如何在SpriteKit中將Sprite旋轉90度

在我的touchesBegan方法,我可以得到雪碧轉動,但是它似乎翻轉本身,而不是真正去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) 
    } 
} 

回答

1

根據你的代碼對我的作品,我會說,這是可能發生的,因爲car.zRotation當前值不爲0.0,而是像-M_PI_2的事實。所以當你將它設置爲M_PI_2時,你會得到180度的旋轉。嘗試在設置新值之前打印car.zRotation