简体   繁体   中英

Set the angle of a sprite in SpriteKit

How would I set the angle of a sprite to 45 degrees?

SKAction *rotate = [SKAction rotateByAngle: M_PI/4.0 duration:1];

only increases the angle by 45 degrees, what I want to do is have to SKSprite rotate however long it takes to get to 45 and then stop. Is there a method for that or will I have to hard code it?

Thanks!

The method you're looking for is +rotateToAngle:duration:shortestUnitArc: , as in:

SKAction *rotate = [SKAction rotateToAngle:M_PI_4 duration:1 shortestUnitArc:YES];

You can also just use +rotateToAngle:duration: , but that always rotates counterclockwise; this variant goes in whichever direction requires the least rotation.

(also note that π/4 is already defined as a constant, M_PI_4 ; see usr/include/math.h)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM