我无法在几秒钟内加载我的纹理。它需要20多秒的时间。
最初,我的动画是分别存储在不同的贴图集中。它们的名称类似于sprite_002@2x~iphone.png
。当它们是分离的时候,我使用了类似于苹果文档中的代码:
SKTextureAtlas *atlas = [SKTextureAtlas atlasNamed:@"monster"];
SKTexture *f1 = [atlas textureNamed:@"monster-walk1.png"];
SKTexture *f2 = [atlas textureNamed:@"monster-walk2.png"];
SKTexture *f3 = [atlas textureNamed:@"monster-walk3.png"];
SKTexture *f4 = [atlas textureNamed:@"monster-walk4.png"];
NSArray *monsterWalkTextures = @[f1,f2,f3,f4];
我的代码是:
let names = myAtlas.textureNames as [String];
for name in names {
myTextureArray.append(myAtlas.textureNamed(name as String));
}
对于6个不同纹理图集中的6个动画,每个动画有250帧,加载大约需要6秒。
我能够消除60-70%的帧并将所有内容压缩到单个纹理图集中,但现在我无法在合理的时间内加载它。
我一直在尝试以下代码:
for i in 1...124 {
let name = String(format: "sprite_%03d", i);
let texture = imagesAtlas.textureNamed(name);
spriteTextures.append(texture);
}
大部分 iPhone 游戏启动时间不会超过 20 秒,所以我知道我这里做错了什么。