iOS7创建和使用SKTextureAtlas的正确方法是什么?

Ale*_*one 3 reference ios7 sprite-kit texture-atlas

我不确定纹理地图集的底层实现,所以我的问题是 - 处理从它们中拉出纹理的正确方法是什么?我需要遍历各种地图集并提取64个随机纹理.

创建静态图集并重用引用来拉出纹理?

static SKTextureAtlas *monsterAtlas;
static int monsterCount;

monsterAtlas = [SKTextureAtlas atlasNamed:@"monsters"];
monsterCount = [monsterAtlas textureNames].count;

//pull out a random texture
NSString* textureName = [[monsterAtlas textureNames] objectAtIndex: arc4random()%monsterCount];
SKTexture* texture = [monsterAtlas textureNamed:textureName];
Run Code Online (Sandbox Code Playgroud)

-要么-

每次我需要纹理时创建一个新的地图集?

SKTextureAtlas *atlas = [SKTextureAtlas atlasNamed:@"monster"];
SKTexture *f1 = [atlas textureNamed:@"monster-walk1.png"];
Run Code Online (Sandbox Code Playgroud)

我问的原因是,使用第一种方法,我的代码可能非常不合适,因为我将创建10个以上的图集引用.这会占用太多内存吗?在第二种方法中,我担心每次执行循环迭代时我都会做很多额外的工作来创建图册.我该怎么做?

Lea*_*s2D 5

创建每个地图集并保留对它的引用.

如果你编写一个管理地图集的类并且可以访问单个纹理,那么这并不是一件好事.