所以我试图在swift 3中使用Sprite工具包构建一个增强现实游戏。我能够将我的相机的视频设置为背景但它出现在我的节点上。基本上,节点位于AVCaptureVideoPreviewLayer下面。如何让我的节点出现在背景上(类似于神奇宝贝go)?我甚至试图改变zPosition,但这不起作用。这是我的代码:
import SpriteKit
import AVFoundation
class GameScene: SKScene {
var captureSession: AVCaptureSession!
var previewLayer: AVCaptureVideoPreviewLayer!
override func didMove(to view: SKView) {
isPaused = false
addPlayer()
scene?.backgroundColor = .clear
captureSession = AVCaptureSession()
let videoCaptureDevice = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo)
let videoInput: AVCaptureDeviceInput
do {
videoInput = try AVCaptureDeviceInput(device: videoCaptureDevice)
} catch {
return
}
captureSession.startRunning()
if (captureSession.canAddInput(videoInput)) {
captureSession.addInput(videoInput)
} else {
return
}
previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
previewLayer.frame = view.layer.bounds
previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
view.layer.addSublayer(previewLayer)
captureSession.startRunning()
}