前面关于旋转的两篇我们利用CABasicAnimation来实现旋转动画,其实在SceneKit中,有一种更为简单的方法去实现一些基础动画,那就是SCNAction,它的执行对象是SCNNode。
一个简单的例子:
SCNAction *shipMoveAction = [SCNAction moveTo:SCNVector3Make(10,10,5) duration:4];
[shipRotationNode runAction:shipMoveAction];
上面代码很容易理解shipRotationNode 动画移动到(10,10,5)这个位置,时间间隔为4s。
我们下面简单介绍一下 SCNAction 主要的API:
+ (SCNAction *)moveByX:(CGFloat)deltaX
y:(CGFloat)deltaY
z:(CGFloat)deltaZ
duration:(NSTimeInterval)duration
//将node从x,y,z上各移动多少距离
+ (SCNAction *)moveBy:(SCNVector3)delta
duration:(NSTimeInterval)duration
//同上,只不过传入参数为SCNVector3
+ (SCNAction *)moveTo:(SCNVector3)location
duration:(NSTimeInterval)duration
//将node移动到location这个位置
+ (SCNAction *)rotateByX:(CGFloat)xAngle
y:(CGFloat)yAngle
z:(CGFloat)zAngle
duration:(NSTimeInterval)duration
//将node从x,y,z上各旋转多少度
+ (SCNAction *)rotateToX:(CGFloat)xAngle
y:(CGFloat)yAngle
z:(CGFloat)zAngle
duration:(