我正在使用SKTextureAtlas(.atlas文件夹)存储我正在使用的动画的帧。我已对帧编号,例如frame.1.png,frame.2.png等-总共有10帧。

我注意到我的动画看起来很恐怖,即使在我的图形程序中预览的帧看起来很棒。我NSLog登出,发现它以随机顺序加载 map 集!我认为它至少会遵循捆绑文件的顺序。我如何在不对数组进行排序的情况下使用捆绑订单。我还要将@ 2x图像与其余图像一起放入,还是创建单独的图集?

SKTextureAtlas *sleighAtlas = [SKTextureAtlas atlasNamed:@"sleigh"];
NSArray *textureNames = [sleighAtlas textureNames];
NSMutableArray *sleighTextures = [NSMutableArray new];
for (NSString *name in textureNames) {
    NSLog(@"texture: %@",name);
    SKTexture *texture = [sleighAtlas textureNamed:name];
    [sleighTextures addObject:texture];
}

其打印输出:



谢谢!

最佳答案

textureNames属性可能包含无序的纹理名称。而不是使用快速枚举,请使用for(;;):

for (int i=0; i < sleighAtlas.textureNames.count; i++) {
    NSString *textureName = [NSString stringWithFormat:@"santaAndSleigh.%d", i];
    [sleighTextures addObject:[explosion2Atlas textureNamed:textureName]];
}

但是,如果将@ 2x图像放入sleighAtlas,则此方法可能行不通。

关于ios - SKTextureAtlas如何按顺序加载纹理,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20364314/

10-12 04:41