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

时间:2013-12-01 04:44:05

标签: 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];

-OR -

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

SKTextureAtlas *atlas = [SKTextureAtlas atlasNamed:@"monster"];
SKTexture *f1 = [atlas textureNamed:@"monster-walk1.png"];

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

1 个答案:

答案 0 :(得分:5)

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

如果您编写一个管理地图集的类并且可以访问单个纹理,那么这不是非常好的。