0

I want to add a glowing animation for a 3D ball

let ball = SCNNode(geometry: SCNSphere(radius: 20))

let highlightAnimation = CABasicAnimation(keyPath: "contents")
highlightAnimation.toValue = UIColor.yellowColor()
highlightAnimation.fromValue = UIColor(hue: 0.01, saturation: 1,
                               brightness: 0.6, alpha: 1) //supposed to be dark red
//other unimportant codes for initialization

ball.geometry!.firstMaterial!.emission.addAnimation(highlightAnimation, forKey: nil)

what happen is, when I run the program, the color changes from bright red (equivalent to UIColor.redColor) to bright yellow instead of the color I want. Apparently the property only accepts the color from default UIColor property. Is there any way to customize the color?

Thanks a lot

  • Use "backgroundColor" keyPath to animate color. – Sandeep Oct 22 '15 at 10:50
  • Have you tried setting the color of the material to your starting dark red before adding the animation? – Gary Makin Oct 22 '15 at 11:04
  • @generatorOfOne it doesnt work. The compiler throws this instead: [SCNKit ERROR] backgroundColor is not an animatable path. Btw can u explain me what keypath is? I cant seem to find it online – Ghifari Rahadian Oct 22 '15 at 12:29
  • @GaryMakin yes I already set it. In fact, I set the geometry by using custom geometry function where I set the diffuse property to a specific color – Ghifari Rahadian Oct 22 '15 at 12:33

0 Answers0