我目前正在开发一款带有SKCameraNode的Spritekit游戏,允许玩家查看战略地图。我试图通过向SKCameraNode添加子节点来实现HUD,但是我遇到了一个关于如何设置子节点坐标的问题。
我将游戏场景初始化为:
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)
在iPhone 7上进行测试,我打印gameScene大小并获得(375, 667)
然后我的相机框架为(667, 375, 0, 0)
但是,在iPhone SE上进行测试时,我会打印gameScene尺寸,并在相机框保持(320, 568)
时获得(667, 375, 0, 0)
的结果
似乎无论我测试什么设备,gameScene都会改变,但相机框架大小相同。这让我无休止地困惑。摄像机从哪里获取其帧参数
此外,我可以使用什么坐标,可靠地用于实际设置HUD?
感谢任何帮助! 谢谢