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

3

我不确定纹理图集的底层实现方式,因此我的问题是 - 正确处理从中提取纹理的方法是什么? 我需要循环遍历各种图集并提取出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个回答

5

仅需创建每个图集一次并保持引用。

如果编写一个管理图集并提供对单个纹理访问的类,则不会使其变得笨重。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接