动画化SKSpriteNode的旋转 [英] Animate rotation of SKSpriteNode

查看:79
本文介绍了动画化SKSpriteNode的旋转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试旋转 SKSpriteNode 以面向 CGPoint 的方向.我已经做到了这样:

I am attempting to rotate an SKSpriteNode to face the direction of a CGPoint. I have managed to do this like so:

CGPoint direction = rwNormalize(offset);

self.player.zRotation = atan2f(direction.y, direction.x);

我怎么称呼它,以使 SKSpriteNode 可以动画化其旋转,而不是瞬时旋转.不管精灵应该旋转到什么位置,动画中还能保持相同的旋转速度吗?预先感谢!

How would I call this so that the SKSpriteNode will animate its rotation rather than it being instantaneous. Would it also be possible to keep the same speed of rotation in the animation no matter where the sprite should turn? Thanks in advance!

推荐答案

使用 SKAction :

CGPoint direction = rwNormalize(offset);
float angle = atan2f(direction.y, direction.x);
// Speed of rotation (radians per second)
float speed = 2.0;

float duration = angle > M_PI_2 ? angle/speed : (angle + M_PI_2)/speed;
[self.player runAction:
    [SKAction rotateToAngle:angle duration:duration]];

这篇关于动画化SKSpriteNode的旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆