3

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.

Fletcher Moore
  • 13,558
  • 11
  • 40
  • 58
  • What font do you use ? Check this out : http://stackoverflow.com/a/23255935/3402095 One discussion about performance in iOS apps http://stackoverflow.com/questions/28041605/sprite-kit-animatewithtextures-lags/28046024#28046024 Maybe some of this will help. – Whirlwind Mar 01 '15 at 15:02

1 Answers1

1

Your load time will be dependent upon the size of your atlases. So if you happen to have a large number of them and they are large, it will take some time.

I've seen variations of this type of question here before.

My suggestion would be to actually change your approach to the problem. This is breaking apart the workload and doing it in the background over time. This is why many games have loading screens.

Depending on your game, you may be able to be extra sneaky and load textures (or any asset for that matter) in the background while the game is playing. More often than not, you don't need to load all your textures at the start of a game.

When I make my games, one of the first things I do is create a background loader, if I don't already have one. I then build the game around the premise of async loading of assets.

20 seconds is pretty long. But based on your description, it sounds like it would take a non trivial amount of time.

Mobile Ben
  • 7,121
  • 1
  • 27
  • 43