I am trying to draw lines into my SKScene
and I can successfully draw it but I want that lines in front of AVCapturePreviewLayer
but I am getting something like this :
I want all the line above my cameraPreviewLayer.
and this is my code for this:
import SpriteKit
import UIKit
import AVFoundation
class GameScene: SKScene {
let captureSession = AVCaptureSession()
var shapeCross:SKShapeNode!
var error: NSError?
override func didMoveToView(view: SKView) {
let devices = AVCaptureDevice.devices().filter{ $0.hasMediaType(AVMediaTypeVideo) && $0.position == AVCaptureDevicePosition.Back }
if let captureDevice = devices.first as? AVCaptureDevice {
captureSession.addInput(AVCaptureDeviceInput(device: captureDevice, error: &error))
captureSession.sessionPreset = AVCaptureSessionPresetPhoto
captureSession.startRunning()
if let previewLayer = AVCaptureVideoPreviewLayer(session: captureSession) {
previewLayer.bounds = CGRectMake(0.0, 0.0, 100, 100)
previewLayer.position = CGPointMake(view.bounds.midX, view.bounds.midY)
previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
previewLayer.opacity = 1
view.scene?.backgroundColor = UIColor.clearColor()
view.layer.addSublayer(previewLayer)
}
}
let bezierPath = UIBezierPath(rect: CGRect(x: 0, y: view.scene!.frame.midY, width: view.scene!.frame.width, height: 1))
bezierPath.appendPath( UIBezierPath(rect: CGRect(x: view.scene!.frame.midX, y: 0, width: 1, height: view.scene!.frame.height)) )
shapeCross = SKShapeNode(path: bezierPath.CGPath)
shapeCross.strokeColor = UIColor.whiteColor()
self.addChild(shapeCross)
}
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
}
override func update(currentTime: CFTimeInterval) {
}
}
I want my previewLayer
behind my SKScene
after that I want to do something like this :
view.scene?.backgroundColor = UIColor.clearColor()
So I can see previewLayer
too and I can see my lines too.
I try to set zPosition of views but its not working.
This is my sample project.