0

Is there a way to load all files from a specific atlas considering that all files names in this atlas are all different ?.

I try the method found on this post Getting a list of files in the Resources folder - iOS it works perfectly but only for basic folder and not with .atlas extension

  NSString * resourcePath = [[NSBundle mainBundle] resourcePath];
  NSString * documentsPath = [resourcePath stringByAppendingPathComponent:@"MYATLAS.atlas"];
  NSError * error;
  NSArray * directoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsPath error:&error];
Community
  • 1
  • 1
Aaleks
  • 4,283
  • 5
  • 31
  • 39

1 Answers1

1

First init your atlas like this:

SKTextureAtlas* myAtlas = [SKTextureAtlas atlasNamed:@"MYATLAS.atlas"];

Then you can load all textures into an dictionary

NSMutableDictionary* texturesDictionary = [NSMutableDictionary dictionary];
for(NSString* textureName in myAtlas.textureNames){
    SKTexture* texture = [myAtlas textureNamed:textureName];
    [texturesDictionary setObject:texture key:textureName];
}

or just preload atlas for later use

[myAtlas preloadWithCompletionHandler:completionHandler];
Dobroćudni Tapir
  • 3,082
  • 20
  • 37