2

I wanted to add a Custom NSView on top of and SKView. However, it is never showing up. Have no clue what is happening...

class GameScene: SKScene {
    override func didMoveToView(view: SKView) {
        //Trying to add Custom View
        let smallView = NSView(frame: NSRect(origin:CGPoint(x: 100,y: 100),   size: CGSize(width: 200, height: 200)))
        let layer = CALayer()
        layer.backgroundColor = CGColorCreateGenericRGB(1.0, 0.0, 0.0, 0.4)
        smallView.layer = layer
        view.superview!.addSubview(smallView)
    }
}

Could anyone who could give me an insight into what is happening here? I even tried adding some NSLabels to the MainStory board. Nothing happens.

I wanted to draw some thing with Coregrapghics and Show on top of the SKScene.But, I can't move forward.

https://github.com/cocoBavan/NSViewInSpriteKit

Alexei
  • 511
  • 1
  • 10
  • 22
Bavan
  • 1,021
  • 1
  • 10
  • 24
  • If you get the latest code, you will see that I somehow got it to work by [1]. Making the NSView a layer-backed view [2]. Adding a delay before attaching it to the SKView once the SKScene is moved to the SKView. I have no clue why it works. Any insights are appreciated. – Bavan Feb 06 '16 at 20:18

1 Answers1

1

Try to add UIView from your ViewController, instead of adding it from SKScene. In your VC add function (for example), create UIView, and then just add it as a subview of a view, like so:

let myView = UIView(frame: CGRect(x: 0, y:0, width: 100, height: 100))
self.view.addSubview(myView)

It will add a new view above existing view, so your GameScene would be below new UIView.

Alexei
  • 511
  • 1
  • 10
  • 22