Reference iOS7创建和使用SKTextureAtlas的正确方法是什么?
我不确定纹理地图集的底层实现,所以我的问题是-如何正确处理从中提取纹理?我需要循环各种地图集并提取64个随机纹理 创建静态图集并重用引用以拉出纹理Reference iOS7创建和使用SKTextureAtlas的正确方法是什么?,reference,ios7,sprite-kit,texture-atlas,Reference,Ios7,Sprite Kit,Texture Atlas,我不确定纹理地图集的底层实现,所以我的问题是-如何正确处理从中提取纹理?我需要循环各种地图集并提取64个随机纹理 创建静态图集并重用引用以拉出纹理 static SKTextureAtlas *monsterAtlas; static int monsterCount; monsterAtlas = [SKTextureAtlas atlasNamed:@"monsters"]; monsterCount = [monsterAtlas textureNames].count; //pull
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];
-或-
每次我需要纹理时创建一个新的地图集
SKTextureAtlas *atlas = [SKTextureAtlas atlasNamed:@"monster"];
SKTexture *f1 = [atlas textureNamed:@"monster-walk1.png"];
我提出这个问题的原因是,使用第一种方法,我的代码可能非常不合适,因为我将创建10多个atlas引用。这会占用太多内存吗?
对于第二种方法,我担心每次执行循环迭代时,我都会做很多额外的工作来创建一个atlas。我应该怎么做呢?创建每个图集一次,并保留对它的引用 如果您编写一个类来管理地图集并允许您访问单个纹理,这并不是不合适的