samedi 28 février 2015

Most performant way to load textures from a Spritekit texture atlas

I cannot figure out how to load my textures in a brief few seconds. It is taking a monster 20+ seconds.


Initially I had my animations in separate texture atlases. They are named something like sprite_002@2x~iphone.png. When they were separate I used code similar to that in the Apple documentation:



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];


My code was:



let names = myAtlas.textureNames as [String];
for name in names {
myTextureArray.append(myAtlas.textureNamed(name as String));
}


For 6 animations in 6 different texture atlases w/ 250 frames each, it took about 6 seconds to load.


I was able to eliminate 60-70% of those frames and cram everything into a single texture atlas, but now I cannot get it to load in a reasonable time frame.


I have been trying code along these lines:



for i in 1...124 {
let name = String(format: "sprite_%03d", i);
let texture = imagesAtlas.textureNamed(name);
spriteTextures.append(texture);
}


Most games iPhone games don't have a 20 second load time, so I know I am doing something wrong here.




Aucun commentaire:

Enregistrer un commentaire