Specifying the background color of a scene in SceneKit

I am trying to specify the background color (which is currently black) on the screen in front of the stage. I searched the documentation and this is what I found:

var background: SCNMaterialProperty { get }

The background to be displayed in front of the rest of the scene. (Read-only) If the material properties content object is zero, SceneKit do not paint any background before painting the rest of the scene. (If the scene is represented in an SCNView instance, the background color of the views is displayed behind the scene content.)

So, I went and sent the content in some color.

scene.background.contents = UIColor.redColor()

      

However, in the moment before the scene, the screen (part of the SCNView) is still black. What am I doing wrong? Perhaps the background property is not what I want? Also, I'm not really sure if you can continue working on some property that only gets (bacground is a getter) and also set some things like in the example code. Thanks for answering

+3


source to share


1 answer


Try setting the backgroundColor property of your SCNView instance. In my code, I have the following: (some of the code may not apply to your situation, but that should give you a general idea.)

if let scene = SCNScene(named: "myScene.scn") {
        ...
  // retrieve the SCNView
  let scnView = self.view as! SCNView

  // set the scene to the view
  scnView.scene = scene

  // configure the view
  scnView.backgroundColor = UIColor.redColor()
}

      



Some of them were created from the Apple template for the SceneKit game. The last line is important. I should mention that I am using Xcode 7 beta with Swift 2 in case there are some subtle differences.

Edit: I seem to have interpreted the question a bit. To change the background color of the view before loading the scene, click on Main.storyboard and in the Interface Builder, click on the View property inside the view controller. Then just set the Background Color property in the Inspector tab.

+3


source







All Articles