使SKScene的背景透明不工作…这是一个错误?
有没有办法让SKScene的背景透明,并通过透明度来呈现另一个场景。
这个想法是有这样的场景的背景:
self.backgroundColor = [SKColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.5f];
什么可以让背后的景象变暗。 但是这样做是行不通的。 背景呈现完全不透明。
有没有办法做到这一点?
在iOS 8中,您可以设置场景的SKView以允许透明度,并将场景的背景色设置为透明。 然后看到SKView背后的景色。
UIView *parentView = ...; [parentView addSubview:backgroundView]; [parentView addSubview:skViewWithScene]; skViewWithScene.allowsTransparency = YES; scene.backgroundColor = [UIColor clearColor]; [skViewWithScene presentScene:scene];
透明度只适用于iOS 8,必须检查iOS 7
在ViewController中设置透明度为:
SKView *skView = (SKView *)self.mySKView; SKScene *skScene = [MyScene sceneWithSize:skView.bounds.size]; skScene.scaleMode = SKSceneScaleModeAspectFill; skView.allowsTransparency = YES; [skView presentScene: skScene];
在MyScene.m中设置背景为清晰的颜色:
self.scene.backgroundColor = [UIColor clearColor];
你不能让场景透明。 如果有什么你想要使视图透明。
但是,您不能同时运行两个场景(只能在两者之间转换),并且可以将多个SKView添加到故事板页面,而只有其中一个视图将全速更新,而其他视图则只会冻结或更改每个视图几秒钟。
我认为这是不可能的,因为尽我所知,我尝试了所有的东西,但却一直忽略了alpha值。
这是不合逻辑的,因为它在OpenGL上工作,但SKView是从UIView,而不是从GLKView subclassed。
迅速3
@IBOutlet var gameScene: SKView! func setupGameScene(){ if let scene = SKScene(fileNamed: "GameScene") { scene.scaleMode = .aspectFill scene.backgroundColor = .clear gameScene.presentScene(scene) gameScene.allowsTransparency = true gameScene.ignoresSiblingOrder = true gameScene.showsFPS = true gameScene.showsNodeCount = true } }