I'm coding a game where when the user loses I want there to be a reset button in the middle of the screen with the rest of it dimmed out. For some reason I can't get transparency to work. I've looked up solutions but couldn't get it to work with mine (there are too many variables that aren't defined) and I can't comment because I don't have enough rep:
Making a SKScene's background transparent not working... is this a bug?
I have a gamescene that extends SKScene where I add all of my SKNodes to a mainView node. I've tried setting the transparency to YES and adding a new skscene with clearColor on top of it but it just shows a black screen:
SKView *dimView = [[SKView alloc] initWithFrame:self.frame];
[self.view addSubview:dimView];
[dimView setBackgroundColor:[UIColor clearColor]];
[dimView setAllowsTransparency:YES];
I know I'm doing something wrong I just don't know what it is. Can anyone pinpoint my mistake?
Update:
I've also tried this and it doesn't work either, also black screen:
CGRect screenRect = [[UIScreen mainScreen] bounds];
//create a new view with the same size
UIView* coverView = [[UIView alloc] initWithFrame:screenRect];
// change the background color to black and the opacity to 0.6
coverView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6];
// add this new view to your main view
[self.view addSubview:coverView];
Update 2:
I've edited the first code set to try to overlay the skview with another skview whose transparency is set to true and color is set to clear color. This way I just get a gray screen. I've been at this for a while and really can't seem to figure out why this isn't working. Any help would be appreciated.
Update 3:
So I think the correct implementation of overlaying a view with another is like so but even with this it still shows a completely black screen:
CGRect screenFrame = [UIScreen mainScreen].bounds;
SKView *dimView = [[SKView alloc] initWithFrame:screenFrame];
SKScene *currentScene = [[SKScene alloc]initWithSize:dimView.bounds.size];
[self.view addSubview:dimView];
[currentScene setBackgroundColor:[[UIColor clearColor] colorWithAlphaComponent:0.5f]];
[dimView setAllowsTransparency:YES];
[dimView presentScene:currentScene];