在游戏的主视图控制器的视图中,我设置了第一层(索引0)和AVCaptureVideoPreviewLayer,并且在视图的上方放置了透明背景的SKView(不透明= NO和backgroundColor = clearColor)但它不是正确的方式,我该怎么办?SpriteKit,如何将现场摄像机放置在背景中
// video capture
AVCaptureSession *session = [[AVCaptureSession alloc] init];
session.sessionPreset = AVCaptureSessionPresetMedium;
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error = nil;
AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error];
[session addInput:input];
AVCaptureVideoPreviewLayer *previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
previewLayer.opaque = YES;
AVCaptureConnection *previewLayerConnection = previewLayer.connection;
if ([previewLayerConnection isVideoOrientationSupported]) {
// aggiunge lo sfondo live solo se supportato dal device
[previewLayerConnection setVideoOrientation:AVCaptureVideoOrientationLandscapeRight | AVCaptureVideoOrientationLandscapeLeft];
previewLayer.frame = self.view.bounds;
[self.view.layer insertSublayer:previewLayer atIndex:0];
[session startRunning];
}
// Create and configure the scene.
GameScene *scene = [GameScene unarchiveFromFile:@"GameScene"];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene
// @property (nonatomic, weak) IBOutlet SKView *skView;
self.skView.opaque = NO;
self.skView.backgroundColor = [UIColor clearColor];
[self.skView presentScene:scene];
尝试'self.skView.alpha = 0'它可能工作,除非你有其他问题与您的意见排序 – Oliver
是不是解决方案,与alpha 0 skView隐藏,包括所有子节点,整个游戏不可见 – Danilo