ARKit开发

16-Actions动作

2020-06-15  本文已影响0人  095b62ead3cd

文章选自掘金苹果API搬运工的文章[SceneKit专题]16-Actions动作
主要记录自己在学习ARKit的过程中看到的好的文章,避免到时候链接失效无法找到原文的情况,非常感谢原博主的辛勤付出,也在此分享出来跟大家一起学习。

动作可以让你操作节点的位置,缩放,旋转和透明度.比如左滑,场景中的小猪向左转并跳一步. 基本分类有四种:Move(移动), Scale(缩放), Rotate(旋转)和Fade(透明渐变).还有两种特殊的动作:Sequence(序列,即顺序执行)和Group(组,即同时执行).

注意,关于物理形体physics body

当需要物理引擎来控制节点的移动和旋转时,应设置为dynamic.如果不需要移动,但仍能参与物理模拟,应设置为static.如果你既想控制某些节点的移动和旋转,同时仍能参与物理模拟,应设置为kinematic.

Move actions移动动作

Scale actions缩放动作

Rotate actions旋转动作

Fade actions褪色动作

Sequenced and grouped actions序列和组动作

序列和组都是一系列动作的组合,可以让动作更复杂


Linear线性,Ease-In渐入,Ease-Out渐出,East-In-Out渐入渐出

The action editor动作编辑器

动作创建

拖放一个旋转动作到节点,设置开始时间和持续时长,指定为绕z轴旋转


右击选中Create Loop,创建循环


选中∞无限循环,当它变蓝时就好了. 不要点X,那会取消


拖动游标预览效果


代码添加动作

// 1.时长
let duration = 0.2
// 2.上下移动动作
let bounceUpAction = SCNAction.moveByX(0, y: 1.0, z: 0, duration:
duration * 0.5)
let bounceDownAction = SCNAction.moveByX(0, y: -1.0, z: 0, duration:
duration * 0.5)
// 3.时间模式
bounceUpAction.timingMode = .EaseOut
bounceDownAction.timingMode = .EaseIn
// 4.动作序列
let bounceAction = SCNAction.sequence([bounceUpAction, bounceDownAction])
// 5.四周移动动作
let moveLeftAction = SCNAction.moveByX(-1.0, y: 0, z: 0, duration:
duration)
let moveRightAction = SCNAction.moveByX(1.0, y: 0, z: 0, duration:
duration)
let moveForwardAction = SCNAction.moveByX(0, y: 0, z: -1.0, duration:
duration)
let moveBackwardAction = SCNAction.moveByX(0, y: 0, z: 1.0, duration:
duration)
// 6.旋转动作
let turnLeftAction = SCNAction.rotateToX(0, y: convertToRadians(-90), z:0, duration: duration, shortestUnitArc: true)
let turnRightAction = SCNAction.rotateToX(0, y: convertToRadians(90), z:
0, duration: duration, shortestUnitArc: true)
let turnForwardAction = SCNAction.rotateToX(0, y: convertToRadians(180),
z: 0, duration: duration, shortestUnitArc: true)
let turnBackwardAction = SCNAction.rotateToX(0, y: convertToRadians(0),
z: 0, duration: duration, shortestUnitArc: true)
// 7.动作组
jumpLeftAction = SCNAction.group([turnLeftAction, bounceAction,
moveLeftAction])
jumpRightAction = SCNAction.group([turnRightAction, bounceAction,
moveRightAction])
jumpForwardAction = SCNAction.group([turnForwardAction, bounceAction,
moveForwardAction])
jumpBackwardAction = SCNAction.group([turnBackwardAction, bounceAction,
moveBackwardAction])
上一篇下一篇

猜你喜欢

热点阅读