skviewsktransition

SpriteKit: Presenting the initial scene wth a transition


I've created multiple transitions from between my game scenes, so I'm unsure why this code is not working.

In my GameViewController, I am simply setting up my TitleScene to appear as the next scene, but I would like it to fade in. I've done this in my touchesBegan succesfully.

Here is the code:

@implementation GameViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Configure the view.
    SKView * skView = (SKView *)self.view;
    skView.showsFPS = NO;
    skView.showsNodeCount = NO;
    /* Sprite Kit applies additional optimizations to improve rendering performance */
    skView.ignoresSiblingOrder = YES;

    // Create and configure the scene.
    SKScene * scene = [TitleScene sceneWithSize:skView.frame.size];
    scene.scaleMode = SKSceneScaleModeResizeFill;

    // Present the scene.
    SKTransition *transition = [SKTransition fadeWithColor:[SKColor blackColor] duration:3.6];
    [skView presentScene:scene transition:transition];

}

Solution

  • You can't use SpriteKit to present the initial scene with a transition because the SKView is (by definition) not showing any scene before the initial scene, so from its perspective there's nothing for it to transition from.

    Presumably, from your point of view, you want to fade into your scene from whatever the user is seeing before SpriteKit gets started — the launch screen of your app, maybe? A common strategy for that is to have the initial storyboard scene contain a UIImageView containing the same image as your launch screen, layered on top of your SKView. When you're ready to start the game, use UIView animateWithDuration:animations:completion: to fade out the image view and remove it from the view hierarchy, and your SKView will be revealed beneath.