在游戏的主视图 Controller 的 View 中,我使用 AVCaptureVideoPreviewLayer 设置第一层(索引 0),在 View 上方我放置了具有透明背景的 SKView(不透明 = NO 且背景颜色 = 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];
最佳答案
尝试将 skView 的 allowsTransparency
属性设置为 true:
skView.allowsTransparency = true
参见Making a SKScene's background transparent not working... is this a bug?了解更多信息。
这有帮助吗?
关于ios - SpriteKit,如何将实时摄像机放置在后台,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32947452/