[英]Does Spritekit (Swift) allow the use of two different Camera nodes?
So I'm working on a project that will require the use of two or more different camera nodes. 因此,我正在一个需要使用两个或更多不同相机节点的项目中。 The problem is that when I call for the second camera node to be activated and used, I get a signal SIGABRT error. 问题是当我要求激活并使用第二个摄像机节点时,出现信号SIGABRT错误。 I think I understand why this error is occurring, since there is already an active camera node. 我想我理解为什么会发生此错误,因为已经有一个活动的摄像机节点。 HOWEVER, my question is whether I can use two camera nodes in one scene, at different times and at different locations. 但是,我的问题是,是否可以在一个场景中的不同时间和不同位置使用两个摄像头节点。 Thank you for any help! 感谢您的任何帮助!
Yes, you can: 是的你可以:
class GameScene: SKScene {
let cam1 = SKCameraNode()
let cam2 = SKCameraNode()
override func didMove(to view: SKView) {
addChild(cam1)
addChild(cam2)
addChild(SKSpriteNode(color: .blue, size: CGSize(width: 50, height: 50)))
cam1.position.x -= 100
cam2.position.x += 100
camera = cam1
}
func swapCam() {
guard let cam = self.camera else { fatalError() }
if cam === cam1 {
camera = cam2
} else if cam === cam2 {
camera = cam1
} else { fatalError() }
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
swapCam()
}
}
Tapping screen hops from left cam1 to right cam2, altering visibility of the built in "hello world" and the blue square I added. 点击屏幕从左cam1到右cam2的跳数,更改内置的“ hello world”和我添加的蓝色方块的可见性。
Your issue has something to do with the SKS file (possibly wrong name?), or for putting the !
您的问题与SKS文件(可能是错误的名称?)有关,或者与!
有关!
at the end of SKCameraNode (not sure why that is there). 在SKCameraNode的末尾(不确定为什么会这样)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.