1

Answers to similar questions like this and this did not solve the problem.

Assigning a SpriteKit scene to the overlaySKScene property of a SCNView does nothing: the SpriteKit scene does not appear at all.

Tested on iPhone 7 and on the Simulator.

Running the code below shows a blank white screen.

@IBOutlet weak var sceneView: SCNView!

override func viewDidLoad() {
    let skScene = SKScene(size: UIScreen.main.bounds.size)
    skScene.backgroundColor = UIColor.black
    let node = SKSpriteNode(imageNamed: "AddButton.png")
    skScene.addChild(node)

    sceneView.overlaySKScene = skScene
    sceneView.overlaySKScene!.scaleMode = .resizeFill
    sceneView.overlaySKScene?.isHidden = false
}
Crashalot
  • 33,605
  • 61
  • 269
  • 439
  • Are you sure it's not there? `backgroundColor` doesn't seem to work on `overlaySKScene` and your node will be added in the corner. Can you see it if you position the node? e.g. `node.position = CGPoint(x: self.view.frame.size.width/2, y: self.view.frame.size.height/2)` – James P Mar 09 '18 at 11:34
  • 1
    @JamesP tried positioning the node, but unfortunately it's not showing up. any other ideas? does the code above work for you? – Crashalot Mar 09 '18 at 22:57
  • It works for me on a default SceneKit project. Is the sceneView actually showing up? – James P Mar 11 '18 at 19:55
  • @JamesP yes the sceneView shows up. hmmm, weird that it works for you. – Crashalot Mar 11 '18 at 20:56
  • We just created a blank project as well to test this, and it's still not working. No button appears. Are you doing anything else besides pasting the code above? – Crashalot Mar 11 '18 at 21:10
  • I can't see in your code where you're setting the SCNScene on the sceneView. That could stop the overlay showing. – James P Mar 12 '18 at 09:15
  • @JamesP where do you set it? we have tried setting it before and after the `scene` property of the SCNView. – Crashalot Mar 12 '18 at 09:59

1 Answers1

1

The following code works for me after setting up a default SceneKit project.

override func viewDidLoad() {
  super.viewDidLoad()
  let scene = SCNScene(named: "art.scnassets/ship.scn")!
  let scnView = self.view as! SCNView
  scnView.scene = scene

  let skScene = SKScene(size: UIScreen.main.bounds.size)
  let node = SKSpriteNode(imageNamed: "testImage.png")
  skScene.addChild(node)

  scnView.overlaySKScene = skScene
  scnView.overlaySKScene!.scaleMode = .resizeFill
}

The overlay view wouldn't show up unless the SCNScene was set on the view, and the background colour of the SKScene had no effect.

James P
  • 4,786
  • 2
  • 35
  • 52