将SpriteKit图集下载到Documents文件夹中

时间:2015-06-12 07:37:09

标签: objective-c iphone sprite-kit atlas

我们正在开发一款拥有大量图像资源的游戏,我们希望将应用程序大小保持在30MB以下,因此决定在zip文件中下载图像。 第一个场景有50个SKSpriteNode对象和426个纹理和动画图像,我们无法创建纹理图集,因为我们的图像不在束中。 从iOS8我们有[SKTextureAtlas atlasWithDictionary:],可以从不在捆绑资源中的图像编译atlasc文件,但我们也必须支持iOS7。 当我们使用[UIImage imageWithContentsOfFile:imagePath][SKTexture textureWithImage:textureImage]方法加载426张图片时,我们的应用会关闭,因为内存使用量很大。

代码:

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

之后:

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

ImagePath宏返回文档目录中给定图像的绝对路径。

是否有最佳做法从SpriteKit中的Documents目录加载大量动画图像?

0 个答案:

没有答案
相关问题