简体   繁体   English

MacOS上的SceneKit OverlaySKScene不可见

[英]SceneKit OverlaySKScene on MacOS not visible

I would like to create a MacOS application using Swift and SceneKit from scratch [using the Cocoa application template]. 我想[使用Cocoa应用程序模板]从头开始使用Swift和SceneKit创建一个MacOS应用程序。 Somehow my overlay SpriteKit scene isn't visible while the same steps do work on iOS. 相同的步骤在iOS上可以正常工作时,以某种方式看不到我的SpriteKit叠加场景。

Steps taken: 采取的步骤:

  • new project > cocoa application 新项目>可可应用
  • add sceneview to main.storyboard 将sceneview添加到main.storyboard
  • add outlet from sceneview to viewcontroller 从SceneView添加出口到ViewController

Code added to viewDidLoad: 添加到viewDidLoad的代码:

// Create scenekit-scene
// ---------------------
let scene = SCNScene()

let nodeCamera = SCNNode()
nodeCamera.camera = SCNCamera()
scene.rootNode.addChildNode(nodeCamera)

let box = SCNBox(width: 1, height: 1, length: 1, chamferRadius: 0)
box.firstMaterial?.diffuse.contents = NSColor.blue
let nodeBox = SCNNode(geometry: box)
nodeBox.position = SCNVector3(0,0, -2)
scene.rootNode.addChildNode(nodeBox)

// Add to view
sceneView.scene = scene


// Create spritekit-scene
// ----------------------
let spriteScene = SKScene(size: CGSize(width: sceneView.frame.width, height: sceneView.frame.height))

let nodelabel = SKLabelNode(fontNamed: "Menlo")
nodelabel.text = "SpriteKit"
nodelabel.fontColor = NSColor.black
nodelabel.position = CGPoint(x: spriteScene.size.width/2, y: spriteScene.size.height/2)
spriteScene.addChild(nodelabel)

// Add to scenekit
sceneView.overlaySKScene = spriteScene

In the iOS-simulator I see a blue cube with black "SpriteKit" in the middle. 在iOS模拟器中,我看到了一个蓝色的立方体,中间是黑色的“ SpriteKit”。 On MacOS I only see the blue cube. 在MacOS上,我只能看到蓝色的立方体。

[BTW: What is kind of strange: when I use the MacOS game template [scenekit] the overlaySKScene functions normal and is visible.] [BTW:有什么奇怪的地方:当我使用MacOS游戏模板[scenekit]时,overlaySKScene功能正常且可见。

So what am I missing? 那我想念什么呢?

While comparing the storyboards scene view properties between the cocoa-template and the game-template I noticed the view controller's view in the cocoa-template had a check-mark in view effects inspector>core animation layer . 在比较可可模板和游戏模板之间的故事板场景视图属性时,我注意到可可模板中视图控制器的视图在视图效果检查器>核心动画层中具有复选标记

When unchecked the OverlaySKScene became visible. 取消选中时,OverlaySKScene变为可见。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM