Frage

I know you can preload spritenodes by creating them at the beginning of the game, but is there a more efficient way of doing this?

War es hilfreich?

Lösung

Refer to SKTexture section on pre-loading textures.

Create SKTexture instead of SKSpriteNode. Then you can use ether preloadWithCompletionHandler: or class method preloadTextures:withCompletionHandler:

A good way to handle preloading is to use texture atlases. By using a texture atlas you combine all of the textures into one larger "sheet" that contains all of them. This allows Sprite Kit to only create one texture object to load into VRAM. Since it then just displays portions of the sprite sheet all of the textures in the atlas can be drawn to the screen with each pass of the GPU.

Here is how I preload my textures using the preloadWithCompletionHandler: method:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{

//  Preload the textures
self.artAtlas = [SKTextureAtlas atlasNamed:@"art"];
[self.artAtlas preloadWithCompletionHandler:^{
//  Textures loaded so we are good to go!

    /* Pick a size for the scene
     Start with the current main display size.
     */
    NSInteger width = [[NSScreen mainScreen] frame].size.width;
    NSInteger height = [[NSScreen mainScreen] frame].size.height;
    JRWTitleScene *scene = [JRWTitleScene sceneWithSize:CGSizeMake(width, height)];

    /* Set the scale mode to scale to fit the window */
    scene.scaleMode = SKSceneScaleModeAspectFit;

    [self.skView presentScene:scene];
}];

#if DEBUG
self.skView.showsFPS = YES;
self.skView.showsNodeCount = YES;
#endif

}

There is a lot more information on preloading textures in the relevant section of the Sprite Kit Programming Guide.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top