3

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?

Diljot Jawanda
  • 69
  • 1
  • 2
  • 5

1 Answers1

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)

enter image description here

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