用在Mac OS塞拉利昂与覆盖SceneKit

问题描述:

我用两个SCNView的绘制我的不正确的界面图和我有一个SpriteKit覆盖(在最高SCNView为HUD相似的特征。 在MacOS 10.11(酋长)的一切精细的作品出来,但在10.12(塞拉利昂)覆盖似乎与背景的alpha混合用在Mac OS塞拉利昂与覆盖SceneKit

比较10.11(预期输出):

macOS 10.11

随着产量的10.12:

macOS 10.12 fully transparent background

视图栈是:

  • SCNView(不透明的黑色背景)
  • SCNView(清晰的背景)
    • SpriteKit覆盖(部分透明的,部分不透明)

黄色正方形(alpha = 0.50)和红色正方形(不透明)来自叠加层。白色立方体绘制在最上面(透明)SCNView中。

当我使背景半透明,多平方变得可见,仍保持透明:

macOS 10.12 semi transparent background

该设置的代码是:

sceneView.scene=SCNScene() 
    sceneView.scene?.rootNode.addChildNode(SCNNode(geometry: SCNBox(width: 10, height: 10, length: 10, chamferRadius: 1))) 

    //An overlay 
    let overlayScene=SKScene(size: CGSize(width: 500, height: 10)) 
    overlayScene.scaleMode = .resizeFill 

    let bar=SKSpriteNode(color: NSColor.yellow.withAlphaComponent(0.5), size: CGSize(width: 250, height: 40)) 
    bar.anchorPoint=CGPoint.zero 

    let smallBar=SKSpriteNode(color: NSColor.red, size: CGSize(width: 250, height: 20)) 
    smallBar.position=CGPoint(x: 125, y: 20) 

    bar.addChild(smallBar) 
    overlayScene.addChild(bar) 

    sceneView.overlaySKScene=overlayScene 

    //Optionally: 
    sceneView.backgroundColor=NSColor.black.withAlphaComponent(0.5) 

我找不到任何能够正确渲染覆盖的东西,比如设置SpriteKit场景的混合模式。

有关如何解决此绘图问题的任何建议?

+0

看起来像线性色彩空间的问题。您可以尝试在您的info.plist中将密钥“SCNDisableLinearSpaceRendering”设置为YES吗? – Toyos

+0

这给出了正确的透明度行为。颜色仍然有点不同。我无法真正找到任何关于它如何工作的真实信息,以及为什么覆盖图会在线性空间渲染的背景上消失。你有一些文件吗? –

有没有什么你不显示我们?它适用于运行10.12的MacBook Pro上使用Xcode 7或Xcode 8创建的项目。也许这是一个显卡问题?

enter image description here

我没有看到你改变SKOverlay的混合模式。所以它默认为每个文档.alpha

重现我的项目,从Xcode SceneKit游戏模板开始。从GameView类中删除mouseDown定义。进口SpriteKit到GameViewController.swift,并更换awakeFromNib这一点:

override func awakeFromNib(){ 
    super.awakeFromNib() 

    // create a new scene 
    gameView.scene=SCNScene() 
    gameView.scene?.rootNode.addChildNode(SCNNode(geometry: SCNBox(width: 10, height: 10, length: 10, chamferRadius: 1))) 

    //An overlay 
    let overlayScene=SKScene(size: CGSize(width: 500, height: 10)) 
    overlayScene.scaleMode = .resizeFill 

    let bar=SKSpriteNode(color: NSColor.yellow.withAlphaComponent(0.5), size: CGSize(width: 250, height: 90)) 
    bar.anchorPoint=CGPoint.zero 

    let smallBar=SKSpriteNode(color: NSColor.red, size: CGSize(width: 250, height: 30)) 
    smallBar.position=CGPoint(x: 125, y: 50) 

    bar.addChild(smallBar) 
    overlayScene.addChild(bar) 

    gameView.overlaySKScene=overlayScene 

    //Optionally: 
    gameView.backgroundColor=NSColor.black.withAlphaComponent(0.5) 

    // create and add a camera to the scene 
    //  let cameraNode = SCNNode() 
    //  cameraNode.camera = SCNCamera() 
    //  gameView.scene!.rootNode.addChildNode(cameraNode) 

    // place the camera 
    //  cameraNode.position = SCNVector3(x: 0, y: 0, z: 15) 

    // create and add a light to the scene 
    let lightNode = SCNNode() 
    lightNode.light = SCNLight() 
    lightNode.light!.type = SCNLight.LightType.omni 
    lightNode.position = SCNVector3(x: 0, y: 10, z: 10) 
    //  gameView.scene!.rootNode.addChildNode(lightNode) 

    // create and add an ambient light to the scene 
    let ambientLightNode = SCNNode() 
    ambientLightNode.light = SCNLight() 
    ambientLightNode.light!.type = SCNLight.LightType.ambient 
    ambientLightNode.light!.color = NSColor.darkGray 
    //  gameView.scene!.rootNode.addChildNode(ambientLightNode) 

    // allows the user to manipulate the camera 
    self.gameView!.allowsCameraControl = true 

    // show statistics such as fps and timing information 
    //  self.gameView!.showsStatistics = true 

} 
+0

感谢您的回答。请从'awakeFromNib()'中删除最后一行。我想你错过了我的(最顶层的)'SCNView'是透明的部分。你的项目会显示和我一样的行为。 –

+0

不仅如此,我错过了关于两个不同SCNView的部分!这是修改后的视图。我想我会在这里留下这个答案,但这不是一个解决方案。 –

+0

有什么让我惊讶的是,你的新屏幕截图并没有显示方块变得透明。当我在我的副本中删除最后一行时,(灰色)背景在两个方格后面都可见,就像在我的第3个截图中一样。 –

如果你的子类SCNView,覆盖viewDidMoveToWindow()方法和方法中没有调用super.viewDidMoveToWindow(),它可能工作。我有一个非常类似的问题添加overlaySKScene到SCNView,这解决了颜色问题。但是,由于某种原因,视图最初可能会闪烁红光。