我使用 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];
}
它的打印输出:
2013-12-04 09:56:54.407 Santa Game[41611:70b] texture: santaAndSleigh.3.png
2013-12-04 09:56:54.407 Santa Game[41611:70b] texture: santaAndSleigh.6@2x.png
2013-12-04 09:56:54.408 Santa Game[41611:70b] texture: santaAndSleigh.8.png
2013-12-04 09:56:54.408 Santa Game[41611:70b] texture: santaAndSleigh.5@2x.png
2013-12-04 09:56:54.408 Santa Game[41611:70b] texture: santaAndSleigh.4.png
2013-12-04 09:56:54.408 Santa Game[41611:70b] texture: santaAndSleigh.9.png
2013-12-04 09:56:54.409 Santa Game[41611:70b] texture: santaAndSleigh.4@2x.png
2013-12-04 09:56:54.409 Santa Game[41611:70b] texture: santaAndSleigh.9@2x.png
2013-12-04 09:56:54.409 Santa Game[41611:70b] texture: santaAndSleigh.5.png
2013-12-04 09:56:54.410 Santa Game[41611:70b] texture: santaAndSleigh.1.png
2013-12-04 09:56:54.410 Santa Game[41611:70b] texture: santaAndSleigh.3@2x.png
2013-12-04 09:56:54.410 Santa Game[41611:70b] texture: santaAndSleigh.6.png
2013-12-04 09:56:54.410 Santa Game[41611:70b] texture: santaAndSleigh.8@2x.png
2013-12-04 09:56:54.411 Santa Game[41611:70b] texture: santaAndSleigh.2@2x.png
2013-12-04 09:56:54.411 Santa Game[41611:70b] texture: santaAndSleigh.2.png
2013-12-04 09:56:54.455 Santa Game[41611:70b] texture: santaAndSleigh.7@2x.png
2013-12-04 09:56:54.456 Santa Game[41611:70b] texture: santaAndSleigh.1@2x.png
2013-12-04 09:56:54.456 Santa Game[41611:70b] texture: santaAndSleigh.10.png
2013-12-04 09:56:54.456 Santa Game[41611:70b] texture: santaAndSleigh.10@2x.png
2013-12-04 09:56:54.457 Santa Game[41611:70b] texture: santaAndSleigh.7.png
谢谢!
最佳答案
可能 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/