SkCamera Node has ambiguous size?

275 Views Asked by At

I'm currently working on a Spritekit Game with a SKCameraNode allowing the player to look at a strategic map. I am trying to implement a HUD by adding child nodes to the SKCameraNode, but I have run into a problem concerning how the coordinates of the child nodes should be set.

I initialize my game scene as so:

    mainScene = GameScene(size: self.view.bounds.size)
    main = view as! SKView

    mainScene.panRecognizer = UIPanGestureRecognizer(target: self, action: #selector(shiftView(recognizer:)))
    main.addGestureRecognizer(mainScene.panRecognizer)

    mainScene.tapRecognizer = UITapGestureRecognizer(target: self, action: #selector(testTap(recognizer:)))
    main.addGestureRecognizer(mainScene.tapRecognizer)

    mainScene.pinchRecognizer = UIPinchGestureRecognizer(target: self, action: #selector(zoomView(recognizer:)))
    main.addGestureRecognizer(mainScene.pinchRecognizer)

    let viewSize = mainScene.size
    mainScene.tempGameBoard.boardCamera.createHUD(size: viewSize, for: mainScene.tempGameBoard.boardCamera.xScale)
    print("cameraframe: \(mainScene.tempGameBoard.boardCamera.frame)")

    main.showsFPS = true
    main.showsNodeCount = true
    main.showsDrawCount = true
    mainScene.scaleMode = .aspectFill
    main.presentScene(mainScene)

Testing on an iPhone 7, I print the gameScene size and get (375, 667) and my camera frame is then (667, 375, 0, 0)

But, testing on an iPhone SE, I print the gameScene size and get a result of (320, 568) while the camera frame remains (667, 375, 0, 0)

It seems no matter what device I test on, the gameScene changes, but the camera frame is the same size. This confuses me endlessly. Where is the camera obtaining its frame parameters from??

Further, what coordinates could I possibly, reliably use to actually setup a HUD?

Appreciate any help! Thank you

0

There are 0 best solutions below