Hunter
Hunter

Reputation: 117

How to make an SKView's background color clear

Hey i have a SubView that is a SKView and its on my controllers main view which is also an skview. So basically the subView-SkView is on the scene perfectly but the square frame of the subview skview stays like a fogy grey/smokey color. The only way i can get the fogy/smokey color off is by putting the alpha of the subview to 0.0 or a really lower number. By the way things to know but probably dont matter is. The subview doesn't have any nodes in it or attached to it. Also it is not apart of a SKScene. It is just the view. I don't know if any of that matters. But here the code below.

 class Scene1: SKScene {


     override func didMoveToView(view: SKView) {
         super.didMoveToView(view)

            var sub = SKView()
            sub = SKView(frame: CGRectMake(self.view!.bounds.width / 1.5, self.view!.bounds.height / 2, self.view!.bounds.width / 3, self.view!.bounds.height / 2))
            sub.alpha = 0.5
            sub.allowsTransparency = true
            sub.opaque = true
            sub.backgroundColor = SKColor.clearColor().colorWithAlphaComponent(0.0)

            view.addSubview(sub)
     }

   }

enter image description here

the white greyness at the bottom of the screen is the subview and this is at the alpha of 0.5

The only thing thats works is changing the alpha other than that the whole subview is covered in a square of smokey fog grey. I wonder if i put an SKNode on the subview will the whole subview frame not be a fogy/grey/smokey color any more. Or do i have to attach the subview to a SKScene. I just dont get why the overall subview frame color want change

Upvotes: 1

Views: 1134

Answers (1)

Ali Beadle
Ali Beadle

Reputation: 4516

As described in this SO question, setting the background colour of an SKView has no effect. You need to add a transparent SKScene to your view to make the whole thing transparent.

Upvotes: 1

Related Questions