[英]SpriteKit, how can place live video camera in the background
In the view of main viewcontroller of the game I set the first layer (index 0) with AVCaptureVideoPreviewLayer, and above of the view i placed the SKView with transparent background, (opaque = NO and backgroundColor = clearColor) but it not is right way, how can I do? 在游戏的主viewcontroller的视图中,我使用AVCaptureVideoPreviewLayer设置了第一层(索引0),在视图上方,我将SKView放置了透明背景(opaque = NO,backgroundColor = clearColor),但这不是正确的方法,我能怎么做?
// 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];
Try setting the allowsTransparency
property of your skView to true: 尝试将allowsTransparency
属性设置为true:
skView.allowsTransparency = true
See Making a SKScene's background transparent not working... is this a bug? 请参见使SKScene的背景透明不起作用...这是一个错误吗? for more info. 有关更多信息。
Did this help? 这有帮助吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.