Crashalot
Crashalot

Reputation: 34523

SceneKit: animation of SCNView background color happens instantly, not gradually

Animating the backgroundColor property of a SCNView happens instantly, instead of gradually over the specified duration.

Here's the code:

UIView.animate(withDuration: 0.5, animations: {
     self.sceneView.backgroundColor = UIColor.redColor
})

This question is similar, but its solutions didn't work. Specifically, setting the backgroundColor beforehand and animating against the layer property did not help.

How can you animate the backgroundColor of a SCNView?

Upvotes: 3

Views: 979

Answers (1)

Confused
Confused

Reputation: 6288

Change the contents of the background material instead. This will give you full SCN Material powers over what the background is, and the ability to use SCN Actions to animate any changes you make.

https://developer.apple.com/documentation/scenekit/scnscene/1523665-background


Better way, and what I'd suggest, is to use CAAnimation. From the docs:

You can attach animations to Scene Kit objects that adopt the SCNAnimatable protocol, including nodes, geometries, and materials.


Generally speaking, the diffuse and ambient colours of a material will be the ones to change to make an appearance adjustment to a background material, depending on how you setup lighting.

Upvotes: 3

Related Questions