SKTextureAtlas如何按顺序加载纹理

Mik*_*e S 5 ios sprite-kit

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

我注意到我的动画看起来很糟糕,即使在我的图形程序中预览的帧看起来很棒.我NSLoged出来,发现它正在以随机顺序加载地图集!我假设它至少会遵循捆绑文件顺序.如何在不自行排序数组的情况下使用捆绑订单.我还将@ 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];
}
Run Code Online (Sandbox Code Playgroud)

它打印出来:

2013-12-04 09:56:54.407圣诞老人游戏[41611:70b]质地:santaAndSleigh.3.png
2013-12-04 09:56:54.407圣诞老人游戏[41611:70b]质地:santaAndSleigh.6@2x.png
2013-12-04 09:56:54.408圣诞老人游戏[41611:70b]质感:santaAndSleigh.8.png
2013-12-04 09:56:54.408圣诞老人游戏[41611:70b]质地:santaAndSleigh.5@2x.png
2013-12-04 09:56:54.408圣诞老人游戏[41611:70b]质地:santaAndSleigh.4.png
2013-12-04 09:56:54.408圣诞老人游戏[41611:70b]质地:santaAndSleigh.9.png
2013- 12-04 09:56:54.409圣诞老人游戏[41611:70b]质地:santaAndSleigh.4@2x.png
2013-12-04 09:56:54.409圣诞老人游戏[41611:70b]质地:santaAndSleigh.9@2x.png
2013-12-04 09:56:54.409圣诞老人游戏[41611:70b]质地:santaAndSleigh.5.png
2013-12-04 09:56:54.410圣诞老人游戏[41611:70b]质地:santaAndSleigh.1.png
2013- 12-04 09:56:54.410圣诞老人游戏[41611:70b]质地:santaAndSleigh.3@2x.png
2013-12-04 09:56:54.410圣诞老人游戏[41611:70b]质地:santaAndSleigh.6.png
2013- 12-04 09:56:54.410圣诞老人游戏[41611:70b]质地:santaAndSleigh.8@2 x.png
2013-12-04 09:56:54.411圣诞老人游戏[41611:70b]质地:santaAndSleigh.2@2x.png
2013-12-04 09:56:54.411圣诞老人游戏[41611:70b]质地:santaAndSleigh. 2.png
2013年12月4日09:56:54.455的Santa游戏[41611:70B]质地:santaAndSleigh.7@2x.png
2013年12月4日09:56:54.456的Santa游戏[41611:70B]质地:santaAndSleigh. 1@2x.png
2013-12-04 09:56:54.456圣诞老人游戏[41611:70b]质地:santaAndSleigh.10.png
2013-12-04 09:56:54.456圣诞老人游戏[41611:70b]质地:santaAndSleigh. 10@2x.png
2013-12-04 09:56:54.457圣诞老人游戏[41611:70b]质地:santaAndSleigh.7.png

谢谢!

And*_*eev 3

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

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

尽管如果您将 @2x 图像放入sleighAtlas.