0

My goal is to add a node which will have sizes equal to the sizes of the window in which the node is presenting.

When I'm trying this:

var screenSize: NSSize!

override func didMove(to view: SKView) {
    screen = self.view?.frame.size

    addCanvasNode()
}

fileprivate func addCanvasNode() {
    canvasNode = SKShapeNode(rect: CGRect(x: -screen.width / 2, y: -screen.height / 2, width: screen.width, height: screen.height))
    canvasNode.fillColor = .brown
    addChild(canvasNode)
}

I get this look:

enter image description here

I do not get why I have those black borders around my node? Why the width and height of my node do not fit the window sizes? What I do wrong?

John Doe
  • 49
  • 1
  • 7

1 Answers1

0

Because it only fits your SKView. You have to configure your SKView to fill the whole window.

  • Yes but for this i need more information from you. Where do you create your SKView? – Jonathan Nov 16 '18 at 12:46
  • In my `ViewController`. It's boilerplate code generated when you create a new project – John Doe Nov 16 '18 at 12:47
  • Yes. But this dont help you because the scene is inside the SKView. – Jonathan Nov 16 '18 at 12:47
  • Okay good to know that you create the SKView programmatically. So when you initialize your SKView, set the frame of the SKView to the frame of your window – Jonathan Nov 16 '18 at 12:48
  • Sry i am actually wrong. I dont have a mac right now , but the View is *inside a SKScene* ... so when you create the scene like `var myScene = SKScene(size: window.size)` – Jonathan Nov 16 '18 at 12:51
  • I cannot do that =/ I cannot get my window properties. `view.window` is always `nil`. OSX is so complicated! – John Doe Nov 16 '18 at 12:52
  • So to get the window size: `window.frame.size` – Jonathan Nov 16 '18 at 12:55
  • I took it from here: https://stackoverflow.com/questions/29205180/resizing-the-window-according-to-a-variable-swift – Jonathan Nov 16 '18 at 12:57
  • So dont use the `view` paramerter from your `didMove(to view: SKView)` because it isnt the window. You need get the size of your window – Jonathan Nov 16 '18 at 12:59
  • To handle Windows here a nice Tutorial: https://www.raywenderlich.com/613-windows-and-windowcontroller-tutorial-for-macos – Jonathan Nov 16 '18 at 13:00