我不确定纹理图集的底层实现方式,因此我的问题是 - 正确处理从中提取纹理的方法是什么? 我需要循环遍历各种图集并提取出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个以上的图集引用。这样会占用太多内存吗? 对于第二种方法,我担心每次执行循环迭代时都要做很多额外的工作来创建图集。我该怎么办?