Duck
Duck

Reputation: 35963

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

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 of the presented scene like this:

self.backgroundColor = [SKColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.5f];

what would allow to see the scene behind darken. But doing this is not working. Background is presented completely opaque.

Is there a way to do that?

Upvotes: 39

Views: 14790

Answers (5)

Ahmed Safadi
Ahmed Safadi

Reputation: 4590

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
    }
}

Upvotes: 5

user1802778
user1802778

Reputation: 81

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];

Upvotes: 7

Jeremy Conkin
Jeremy Conkin

Reputation: 1244

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];

Upvotes: 77

CodeSmile
CodeSmile

Reputation: 64477

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.

Upvotes: 2

Kex
Kex

Reputation: 776

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.

Upvotes: 1

Related Questions