如何为我的节点淡化/过渡?

时间:2017-01-13 17:28:25

标签: swift scenekit

我希望定期更改我的SCNBox的颜色,例如,游戏展开使其节点平滑地过渡颜色。

        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)

    }

提前致谢!

1 个答案:

答案 0 :(得分:1)

你可以用隐式动画做这样的事情:

   // Objective-C

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