As seen in https://developer.apple.com/wwdc20/10614 light color could be changed and animated. I would like to know if it Is possible with the current state of GameController API to implement animation of .color property of GCController.light.
Animating GCColor.
So I made a little code snippet that will animate the GCColor. Just add it to your class and call animate(to:,duration:,completion:) to animate the DualShock controller's color.
Code Block var completions: [() -> ()] = [] func animate(to color: GCColor, duration: TimeInterval, _ completion: (() -> ())? = nil) { completions.removeAll() let currentColor = controller.light!.color let diff = (color.red - currentColor.red, color.green - currentColor.green, color.blue - currentColor.blue) let steps = Int(duration * 20) for i in 0..<steps { completions.append { self.controller.light?.color = GCColor(red: currentColor.red + Float(i) * diff.0 / Float(steps), green: currentColor.green + Float(i) * diff.1 / Float(steps), blue: currentColor.blue + Float(i) * diff.2 / Float(steps)) self.completions.removeFirst() self.animate(steps: steps, duration: duration, completion) } } completions.first?() } func animate(steps: Int, duration: TimeInterval, _ completion: (() -> ())?) { DispatchQueue.main.asyncAfter(deadline: .now() + duration / Double(steps)) { if self.completions.isEmpty { completion?() } else { self.completions.first?() } } }
So I've just made this into a gist!