user2391236
user2391236

Reputation:

How to load iOS7 app scene before playing the game?

So I've been writing my first iOS app, learning objective-C and sprite kit. My "scene" is getting pretty populated and whenever I run the game in the simulator, the first fourth of a second the game kinda "jitters" and is hard to control, but then from there on out runs at 60.0fps. How do I get the scene to completely load and be ready to play before it actually starts?

Upvotes: 1

Views: 149

Answers (1)

sangony
sangony

Reputation: 11696

Testing on a simulator will never give you accurate FPS. Always test on an actual device.

Use a texture atlas for your images. You can get more information on texture atlases from the Sprite Kit Programming Guide.

Below is a code samples of how to preload a texture Atlas:

-(void)loadMyAtlas
{
    SKTextureAtlas *myAtlas = [SKTextureAtlas atlasNamed:@"TextureAtlasName"];
    [SKTextureAtlas preloadTextureAtlases:[NSArray arrayWithObject:myAtlas] withCompletionHandler:^{
        // do something here
    }];
}

Texture Packer is a free app, from CodeAndWeb, which allows you to easily create a texture atlas, including animations. Try it out.

CodeAndWeb also has an interesting article on preloading practices, texture atlases and animations.

To be complete, as prototypical suggested, here are ways to preload sound as well as fonts:

Create an iVar SKAction *someSound; then place the following code with the loading code of your scene someSound = [SKAction playSoundFileNamed:@"soundFileName.mp3" waitForCompletion:NO]; To play the sound use [self runAction:someSound];

Prototypical answered a question on preloading fonts:

The delay is based on the loading of your font. Best to preload fonts, sounds, and any other assets you intend to use, so that you don't have a delay when it's actually used the first time.

You can preload in your setup with : SKLabelNode *preload = [SKLabelNode labelNodeWithFontNamed:@"System"];

Upvotes: 1

Related Questions