SKSpriteNode zrotation M_PI infuriates

so all I want to do is rotate SKSPriteNode

90 degrees. just that. It should be simple, but my first approach, assuming it will be a degree, completely turns the subject into a wrong diet. so I'm heading to google> stackoverflow. many answers to do with this good, so try to use M_PI

or some options. Nope. "Double" is not converted to "CGFloat". google again. "Try skaction with blah blah" nope.

How difficult is it to rotate a sprite? or am i crazy

+3


source to share


3 answers


I assume you are using Swift based on your comment "Double 'is not convertible ...".

The next rotation of the sprite is 90 degrees counterclockwise:

        sprite.runAction(SKAction.rotateByAngle(CGFloat(M_PI_2), duration: 1.0))

      



The next rotation of the sprite is 90 degrees clockwise:

        sprite.runAction(SKAction.rotateByAngle(CGFloat(-M_PI_2), duration: 1.0))

      

+2


source


This seems to work fine for me. Understanding the transitions between radians and degrees is important. http://en.wikipedia.org/wiki/Radian#Conversion_between_radians_and_degrees



sprite.zRotation = CGFloat (M_PI_2)

+3


source


Another option is to create an extension for Int extension Int { var deg2Rad : CGFloat { return CGFloat(self) * CGFloat(M_PI) / 180.0 } }

then use it like this:

sprite.runAction (SKAction.rotateByAngle (180.deg2Rad, duration: 1.0))

Makes it more human-readable I think

0


source







All Articles