Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SKSpriteNode zrotation M_PI is infuriating

so all i want to do is rotate an SKSPriteNode by 90 degrees. just that. It should be simple yet my first approach, assuming it would be degrees, turns the object in completely the wrong diection. so i head to google > stackoverflow. plenty of answers to do with this, okay so ill try using M_PI or some variation. nope. 'Double' is not convertible to 'CGFloat'. google again. "Try using skaction with blah blah" nope.

how difficult can it be to rotate a sprite? or am i insane

like image 813
invisibloom Avatar asked Mar 18 '23 09:03

invisibloom


2 Answers

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

sprite.zRotation = CGFloat(M_PI_2)

like image 141
baskInEminence Avatar answered Mar 24 '23 02:03

baskInEminence


I'm assuming you're using Swift based on your "'Double' is not convertible..." comment.

The following rotates a sprite 90 degree counterclockwise:

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

The following rotates a sprite 90 degree clockwise:

sprite.runAction(SKAction.rotateByAngle(CGFloat(-M_PI_2), duration: 1.0))
like image 30
0x141E Avatar answered Mar 24 '23 01:03

0x141E