【发布时间】:2015-02-04 02:24:00
【问题描述】:
我正在寻找一种在 SceneKit 中为精灵表设置动画的方法。经过一番研究,我找到了 Core Animation 方法来做到这一点,这将是完美的,因为我需要尽可能多地控制动画。
我准备了一个简单的平面网格,它的 UV 限制为一个 spritesheet 框架的大小。这样我只需要水平地为 UV 设置动画。我发现材质的 contentsTransform 矩阵的相关元素是 m14(负责水平平移的元素)。
但是,在运行时,SceneKit 会返回以下错误:
[SCNKit ERROR] geometry?.firstMaterial?.diffuse.contentsTransform.m14 is not an animatable path
这是相关代码:
let spritesheetAnimation = CABasicAnimation(keyPath: "geometry?.firstMaterial?.diffuse.contentsTransform.m14")
spritesheetAnimation.fromValue = 1 - 1 / spritesheetFrameCount
spritesheetAnimation.toValue = 0
spritesheetAnimation.byValue = 1 / spritesheetFrameCount
spritesheetAnimation.duration = 1.0
spritesheetAnimation.repeatCount = Float.infinity
node.geometry?.insertMaterial(material, atIndex: 0)
node.addAnimation(spritesheetAnimation, forKey: "SpritesheetAnimation")
有人有这方面的经验吗?我不知道是否有更简单的方法可以做到这一点,或者我是否以错误的方式看待它或其他任何事情。因此,任何指针将不胜感激!
【问题讨论】:
标签: animation swift core-animation scenekit