Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift SpriteNode Initial Angle

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?

like image 753
Diljot Jawanda Avatar asked Jul 29 '26 07:07

Diljot Jawanda


1 Answers

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.

like image 107
Luca Angeletti Avatar answered Aug 01 '26 15:08

Luca Angeletti