0

考虑到此图集中的所有文件名都不同,有没有办法从特定图集中加载所有文件?

我尝试在这篇文章中找到的方法 获取资源文件夹中的文件列表 - iOS 它可以完美运行,但仅适用于基本文件夹而不是 .atlas 扩展名

  NSString * resourcePath = [[NSBundle mainBundle] resourcePath];
  NSString * documentsPath = [resourcePath stringByAppendingPathComponent:@"MYATLAS.atlas"];
  NSError * error;
  NSArray * directoryContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:documentsPath error:&error];
4

1 回答 1

1

首先像这样初始化你的图集:

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

然后您可以将所有纹理加载到字典中

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

或者只是预加载图集以备后用

[myAtlas preloadWithCompletionHandler:completionHandler];
于 2014-05-07T12:28:56.783 回答