Tiptonix Beats Tiptonix Beats - 4 months ago 13
iOS Question

What is the equivalent of colorizing an object in SceneKit?

How can I animate a change in color of an

SCNNode
? In
SpriteKit
I would just use the
colorizeWithColor SKAction
, but that is not an option in
SceneKit
. In
SpriteKit
, I would typically have a collision between two nodes. When the nodes collided one of the nodes changed colors simply by running the
colorizeWithColor SKAction
. What's the equivalent of this in
SceneKit
for an
SCNNode
?

Answer

You can use the multiply property of your material to achieve a similar effect. You can set the fade length with SCNTransaction's animationDuration property.

SCNTransaction.begin()
SCNTransaction.animationDuration = yourFadeDuration
geometry?.firstMaterial?.multiply.contents = yourDesiredColor
SCNTransaction.commit()