invisibloom invisibloom - 5 months ago 38
Objective-C Question

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

Answer

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))
Comments