I'm looking for a way to animate sprite sheets in SceneKit. After some research I found the Core Animation way to do this, which would be perfect as I need as much control over the animation as possible.
I've prepared a simple plane mesh, with its UVs limited to one spritesheet frame's size. That way I'd only need to animate the UVs horizontally. I've found that the relevant element of the material's contentsTransform matrix would be m14 (the one responsible for horizontal translation).
However, at runtime, SceneKit spits back the following error:
[SCNKit ERROR] geometry?.firstMaterial?.diffuse.contentsTransform.m14 is not an animatable path
This is the relevant code:
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")
Anyone having experience with this? I don't know if there's an easier way to do this, or if I'm looking at it the wrong way or anything. So, any pointers would be appreciated!