Clinton Lam
Clinton Lam

Reputation: 727

Getting rotation details from SKAction.rotateToAngle() - SpriteKit

The following code will animate a rotation when start() is called and stop the motion when stop() is called.

func start(){
  let rotate = SKAction.rotateToAngle(CGFloat(M_PI), duration: 10.0)
  something.runAction(SKAction.sequence([rotate]))
}

func stop(){
  something.paused = true
  // or 
  // something.removeAllActions()
}

Now, when stop() is called within the animation period (e.g. 5sec into the action in this case), can I get how much the object has rotated at the particular moment, in radian?

I want to know the rotated angle for a given spriteNode between user taps. Is there any other ways to achieve that?

Upvotes: 0

Views: 109

Answers (1)

Jim Driscoll
Jim Driscoll

Reputation: 904

All SpriteKit nodes (SKNode) have a zRotation property which tells you this (rotation around the z axis, which is the axis which points into/out of the screen)

https://developer.apple.com/library/prerelease/ios/documentation/SpriteKit/Reference/SKNode_Ref/index.html#//apple_ref/occ/instp/SKNode/zRotation

Upvotes: 0

Related Questions