Making a SKScene's background transparent not working… is this a bug?

前端 未结 5 704
挽巷
挽巷 2020-12-03 06:52

Is there a way to make a SKScene\'s background transparent and present that scene over another one seeing thru the transparency.

The idea is to have the background o

相关标签:
5条回答
  • 2020-12-03 07:03

    swift 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
        }
    }
    
    0 讨论(0)
  • 2020-12-03 07:12

    I think that's not possible, since I tried everything as far as my knowledge goes, it keeps ignoring the alpha value.

    Which is not logical since it works on top of OpenGL, but the SKView is subclassed from UIView, not from GLKView.

    0 讨论(0)
  • 2020-12-03 07:19

    Transparency works only for iOS 8, have to check for iOS 7

    In the ViewController set transparency as :

    SKView *skView = (SKView *)self.mySKView;
    SKScene *skScene = [MyScene sceneWithSize:skView.bounds.size];
    skScene.scaleMode = SKSceneScaleModeAspectFill;
    skView.allowsTransparency = YES;
    [skView presentScene: skScene];
    

    In MyScene.m set background as clear color:

    self.scene.backgroundColor = [UIColor clearColor];

    0 讨论(0)
  • 2020-12-03 07:22

    In iOS 8, you can set the scene's SKView to allow transparency and set the scene's background color to have transparency. Then views behind the SKView will be seen.

    UIView *parentView = ...;
    [parentView addSubview:backgroundView];
    [parentView addSubview:skViewWithScene];
    skViewWithScene.allowsTransparency = YES;
    scene.backgroundColor = [UIColor clearColor];
    [skViewWithScene presentScene:scene];
    
    0 讨论(0)
  • 2020-12-03 07:22

    You can't make the scene transparent. If anything you'll want to make the view transparent.

    However you can't have two scenes running at the same time (only transitioning between them), and while you can add multiple SKView to a Storyboards page only one of the views will update at full speed, they other frozen or changing contents only every couple seconds.

    0 讨论(0)
提交回复
热议问题