0

このアトラスのすべてのファイル名がすべて異なることを考慮して、特定のアトラスからすべてのファイルをロードする方法はありますか?

この投稿で見つかった方法を試し ます Resourcesフォルダー内のファイルのリストを取得する -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 に答える