4

I have a main view of type UIView. This view has two skview's (left and right) in landscape only orientation. All views and scenes are set with a black background.

I start out with the two skviews hidden. The main screen shows questions on either side of the screen. If the answer is incorrect I set a scene to an effect and then enable that effect and unhide the skview (left or right). The effect is shown for several seconds after which I disable it with [self.leftView presentScene:nil]; I do the same with the rightView. I then hide the views again.

The issue is that when the scenes are shown there is a brief flash of the view in a white color before the scene is rendered appropriately with the black background. In fact this is why I took to hide the skviews to begin with as if I don't they will show with a lighter background despite my setting it to black.

How can I show these scenes without the flash of a lighter background color?

Some representative code:

self.fireSceneLeft = [FireScene sceneWithSize:self.leftView.bounds.size];
self.fireSceneLeft.scaleMode = SKSceneScaleModeAspectFill;
self.fireSceneLeft.backgroundColor = [UIColor blackColor];

[self.leftView presentScene:self.fireSceneLeft];
    [self.leftView setHidden:NO];

As for the scene effect itself:

    @implementation FireScene

-(SKEmitterNode *)fireEffect
{
    SKEmitterNode *emitter =  [NSKeyedUnarchiver unarchiveObjectWithFile:[[NSBundle mainBundle] pathForResource:@"FireEffect" ofType:@"sks"]];
    emitter.position = CGPointMake(150,80);
    emitter.name = @"fire";
    emitter.targetNode = self.scene;
    emitter.numParticlesToEmit = 2;
    return emitter;
}

-(void)update:(CFTimeInterval)currentTime {

    [self addChild:[self fireEffect]];
}

@end
rmaddy
  • 314,917
  • 42
  • 532
  • 579
C6Silver
  • 3,127
  • 2
  • 21
  • 49
  • It looks like an SKView has a gray background until a scene with a different color is rendered. I cannot get the unfilled SKView to have a black background. I think as the scene is removed and then a new one is rendered that it's flashing that default gray. If I put an SKView on a UIView and do nothing else it shows gray no matter what I tell it to set the background color to. – C6Silver May 06 '14 at 15:55

2 Answers2

1

I solved this issue by creating another scene that is simply black. Instead of setting the scene I want to move away from to nil, I simply substitute in the black scene. A scene with nothing on it (blank SKView) has a gray color which is the cause of my problem. By starting the app with the black scene and using it when no scene should display, my problem was solved. An important point here as well is pausing the scene. Even a black scene with no movement will use up CPU if not paused. I found the best place to pause the black scene was in the following method of the scene controller:

-(void)update:(CFTimeInterval)currentTime {

[self addChild:[self blackEffect]];
[self.view setPaused:YES];

}

This was also tricky because pausing the scene elsewhere actually paused the older scene. This is a timing problem because even if you call a new scene and then pause, it won't have had the time to get the new scene in place before the pause. The method above was the only place I could reliably call the pause and have it take effect on the correct scene.

C6Silver
  • 3,127
  • 2
  • 21
  • 49
0

On iOS you can't have 2 (or more) SKView instances at the same time. While it works technically and on first sight it is actually unusable because one view will dominate the other(s), leaving very little time for the other view(s) to update and render their contents as well as receiving touch and other events. I suspect the brief flash is related to this.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
  • There does not need to be two views running for this to happen. For example, a user can get a question on the left wrong which brings up a fire effect on the left while the skview on the right is sitting dormant. The flash will still occur on this left hand side. Again, both views don't need to be rendering a scene for this to happen. – C6Silver May 06 '14 at 06:34