在 SceneKit 中指定场景的背景颜色

pot*_*ato 6 scene ios scenekit

我试图在场景出现之前指定屏幕的背景颜色(当前为黑色)。我搜索了文档,这是我发现的:

\n\n
\n

var background: SCNMaterialProperty { get }

\n\n

在场景的其余部分之前渲染的背景。(只读)\n 如果材质属性\xe2\x80\x99s 内容对象为 nil,则 SceneKit 在绘制场景的其余部分之前\n 不会绘制任何背景。(如果场景在 SCNView 实例中呈现,则视图\xe2\x80\x99s 背景色\n 在场景内容后面可见。)

\n
\n\n

所以我去把内容发送到某种颜色。

\n\n
scene.background.contents = UIColor.redColor()\n
Run Code Online (Sandbox Code Playgroud)\n\n

然而,在场景渲染之前,屏幕(其中的 SCNView 部分)仍然是黑色的。我究竟做错了什么?也许背景属性不是我需要的?另外,我不太确定是否可以进一步深入某些仅 get(bacground 是 getter)的属性,而不是像我在代码示例中那样设置一些内容。谢谢回答

\n

Syl*_*van 6

尝试设置 SCNView 实例的 backgroundColor 属性。在我的代码中,我有以下内容:(某些代码可能不适用于您的情况,但它应该为您提供总体思路。)

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()
}
Run Code Online (Sandbox Code Playgroud)

其中一些是根据 Apple 的 SceneKit 游戏模板生成的。最后一行是重要的一行。我应该提到我正在使用 Xcode 7 beta 和 Swift 2,以防存在一些细微的差异。

编辑:似乎我有点误解了这个问题。要在加载场景之前更改视图的背景颜色,请单击 Main.storyboard,然后在 Interface Builder 中单击视图控制器内的 View 属性。然后只需在“检查器”选项卡中设置“背景颜色”属性即可。