1

I have the exact same problem as described here, however the proposed solution won't work. In short, when transitioning between scenes, the transition in between is skipped entirely because the presentee takes too long to load. Now I'm looking for a way to properly preload all contents of the scene. What I do is:

  1. alloc/init the scene upon application launch
  2. preload all textures the scene consists of thereafter
  3. a few seconds later, present the scene.

The first time a transition is triggered it is always skipped, all following attempts work as expected.

Here is an example of how I alloc/init and preload the scenes (upon launch):

self.menuScene = [[LEMenuScene alloc] initWithSize:self.bounds.size];
[self.menuScene preload];

whereby preload is a category of SKScene:

- (void) preload {
    NSMutableArray* allTextures = [[NSMutableArray alloc] init];
    [self enumerateChildNodesWithName:@"//SKSpriteNode" usingBlock:^(SKNode *node, BOOL *stop) {
        SKTexture* texture = ((SKSpriteNode*)node).texture;
        if (texture) [allTextures addObject: texture];
    }];

    [SKTexture preloadTextures:allTextures withCompletionHandler:^{
        //nop
    }];
}

I am aware that the loading is carried out asynchronously and that preload will return instantly (which is intended), so I could cause a transition before loading is finished, but it does not matter how long I wait, it always lags.

Any tips/help is greatly appreciated!

Community
  • 1
  • 1
Double M
  • 1,449
  • 1
  • 12
  • 29
  • Are you sure preloading has finished before transition? Do you start the transition inside the `preloadTextures` completionHandler? Or try to put an NSLog inside the completionHandler and right before transitioning and see which is logged first. – CloakedEddy Aug 06 '15 at 09:55
  • Thanks for the tip, but yes, I am sure. The transition is started by the press of a button (not from inside the completion handler), but only after a completion message was logged. So in spite of having finished preloading it lags. – Double M Aug 06 '15 at 13:09
  • 1
    Perhaps a simple question but you are sure you are presenting the preloaded menuScene instance (and not another one)? If so, it looks good. Then, the problem wil be hard to pinpoint without posting more of the `LEMenuScene` implementation code. – CloakedEddy Aug 06 '15 at 13:29

1 Answers1

0

Turns out the issue wasn't the textures after all. I misspelled the name of a font, which made the system look for a suitable substitution, causing the delay.

Here's the same issue: How to cache or preload SKLabelNode font?

Community
  • 1
  • 1
Double M
  • 1,449
  • 1
  • 12
  • 29