【发布时间】:2017-10-21 07:31:18
【问题描述】:
我在使用 SceneKit 动画时遇到了我不理解的行为。 以下所有代码都在渲染器的上下文中执行:updateAtTime: 委托调用。
我这样构建我的动画:
SCNVector4 startRotation = node.rotation ;
SCNVector4 targetRotation = pose.rotation ;
CABasicAnimation *rotAnimation = [CABasicAnimation animationWithKeyPath:@"rotation"] ;
rotAnimation.fromValue = [NSValue valueWithSCNVector4:startRotation] ;
rotAnimation.toValue = [NSValue valueWithSCNVector4:targetRotation] ;
rotAnimation.duration = duration ;
现在,如果我在之后这样做:
// First change the final rotation state, and then start the animation
node.rotation = targetRotation ;
[node addAnimation:rotAnimation forKey:animationName] ;
我在最终位置快速闪现了角色,然后动画从 startRotation 运行到 targetRotation 并永远保持在 targetRotation 位置 - 这是我想要的,除了 flash。
如果我这样做(只需交换最后两行的顺序):
// First start the animation and then set the final position
[node addAnimation:rotAnimation forKey:animationName] ;
node.rotation = targetRotation ;
我没有闪光灯,但是当动画结束时,角色回到初始位置,这不是我想要的。
我阅读了有关fillMode 和removedOnCompletion 的信息,但是将removedOnCompletion 设置为NO 是不正确的做法,因为它会使动画永远“运行”。
如何避免初闪?
【问题讨论】:
-
我认为您应该在
renderer:updateAtTime:之外制作动画,因为文档说任何场景更改都会立即应用。 (所以我猜在添加动画之前节点会更新。) -
好吧,几乎...我认为当您说“在渲染器之外制作动画:updateAtTime:”时您是对的。但是,并不是因为更改会立即应用。我经历了漫长的调查,我想我现在明白发生了什么。简而言之,如果在 renderer:didRenderScene:atTime: 中执行,我的代码可以完美运行(没有 flash)。为了记录和帮助他人,我将写一个详细的解释并回答我自己的问题。