문제

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];
도움이 되었습니까?

해결책

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];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top