Reputation: 83
Im trying to add rotation to a sprite by 90 degrees, so if i tap above it, it moves 90 degrees an faces that direction. Think like snake game.
In my touchesBegan method i can get the Sprite to rotate, however it seems to flip itself and not actually go 90 degrees, more like 180.
Any ideas why and how I could get it to point in the correct direction.
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)
}
}
Upvotes: 1
Views: 1112
Reputation: 13665
Based on the fact that your code works for me I would say that this is probably happening because the current value of car.zRotation
is not 0.0 but rather something like -M_PI_2
. So when you set it to M_PI_2
you get a rotation of 180 degrees. Try to print car.zRotation
before you set a new value .
Upvotes: 1