I'm trying to set the initial angle of my sprite to be 90 degrees. I don't want to call an action, is there a way of setting the angle parameter of a sprite as you do with the position?
Asked
Active
Viewed 276 times
1 Answers
1
zRotation
You can use the zRotation
property of SKNode
which accept radiants
Degrees to Radiants
There's a useful extension for that
extension Int {
var degreesToRadians: Double { return Double(self) * M_PI / 180 }
var radiansToDegrees: Double { return Double(self) * 180 / M_PI }
}
sprite.zRotation = CGFloat(90.degreesToRadians)
From the Api Doc
The Euler rotation about the z axis (in radians).
The default value is 0.0, which indicates no rotation. A positive value indicates a counterclockwise rotation. When the coordinate system is rotated, it affects the node and its descendants. The rotation affects the node’s frame property, hit testing, rendering, and other similar characteristics.
The Yoshi's Island image comes form here.

Community
- 1
- 1

Luca Angeletti
- 58,465
- 13
- 121
- 148
-
1Parameters are in Radians and not degrees, so 90 won't work. Instead I put M_PI_2 – Diljot Jawanda Aug 19 '16 at 21:15
-
1Shouldn't the extension return a `CGFloat` instead of a `Double`? – 0x141E Aug 21 '16 at 08:57
-
Where, in the code of a game, should an extension to Int be? – Confused Oct 02 '16 at 15:38