Vicious Vexx
Vicious Vexx

Reputation: 27

How can I color fade/transition my node?

I am looking to periodically change the color of my SCNBox for example, the game unfold has its nodes transitioning colors smoothly.

        let base = SCNBox(width: 1, height: 1, length: 1, chamferRadius: 0)
        let emptyBase = SCNNode(geometry: base)
        emptyBase.position = SCNVector3(0, 0.5, 0)

        emptyBase.physicsBody = SCNPhysicsBody.kinematic()
        //emptyBase.physicsBody!.restitution = 1

        emptyBase.physicsBody!.categoryBitMask = CC.base.rawValue


        if #available(iOS 9.0, *) {
            emptyBase.physicsBody!.contactTestBitMask = CC.ball.rawValue
        } else {
            // Fallback on earlier versions
            emptyBase.physicsBody!.collisionBitMask = CC.ball.rawValue
        }


            if GameViewController.gameOverlay!.scoreNumber >= 0 {

                let defaultMaterial = SCNMaterial()

                    defaultMaterial.diffuse.contents = randomColor()
                    defaultMaterial.specular.contents = randomColor()
                    defaultMaterial.emission.contents = randomColor()

                base.firstMaterial? = defaultMaterial


            }

        rootNode.addChildNode(emptyBase)

    }

Thanks in advance!

Upvotes: 0

Views: 260

Answers (1)

sambro
sambro

Reputation: 816

You could do something like this with implicit animation:

   // Objective-C

        [SCNTransaction setAnimationDuration:2.0];
        base.firstMaterial = defaultMaterial;

Upvotes: 1

Related Questions