ios - SKTextureAtlas如何按顺序加载纹理

标签 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];
}

它的打印输出:

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/

相关文章:

ios - 无论屏幕尺寸如何,如何在正确的位置显示 Sprite

ios - 如果应用程序在 iOS 上未激活,我怎么知道联系人已被修改?

ios - UIView 的问题,animateWithDuration 和完成

android - Unity3D 初学者和游戏设计

ios - SKTileMapNode:创建无限大小的瓦片 map

ios - 如何在didMoveToView(Swift,SpriteKit)中注册触摸?

ios - Xcode 8 UIImagePickerController 卡住

objective-c - 没有 NavigationBar 的 UINavigationController

ios - Xcode SpriteKit Game - 如何在应用程序安装过程中为多种屏幕尺寸配置 UI

ios - 确保节点可见