Download SpriteKit atlas into Documents folder

202 views Asked by At

We are developing a game that have a lot of image assets and we want to keep the app size under 30MB so decided to download images within a zip file. The first scene have 50 SKSpriteNode object and 426 images for textures and animations and we cannot create texture atlas because our images are not in the bundle. From iOS8 we have [SKTextureAtlas atlasWithDictionary:] that can compile atlasc files from images that aren't in the bundle resources but we have to support iOS7 too. When we load 426 images with [UIImage imageWithContentsOfFile:imagePath] and [SKTexture textureWithImage:textureImage] methods our app shut down because the large memory usage.

Code:

for (int i=0; i <= numImages-1; i++) {
    NSString *textureName = [NSString stringWithFormat:@"texture_%05d", i];
    SKTexture *texture = [SKTexture textureWithImage:ImagePath(textureName)];
    [frames addObject:texture];
}

And after:

SKAction *action = [SKAction animateWithTextures:frames timePerFrame:kAnimationFrameTime resize:YES restore:YES];
[node runAction:action withKey:kAnimationActionKey];

ImagePath macro returns with the absolute path for the given image in the Documents directory.

Is there any best practice to load large amount of images for animation from Documents directory in SpriteKit?

0

There are 0 answers