我使用了一个SKTextureAtlas (.atlas文件夹)来存储我正在使用的动画的框架。我已经对帧进行了编号,比如Fra.1.png,frames,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:56:54.407圣诞老人游戏41611:70B纹理: santaAndSleigh.3.png 2013年-12-04 09:56:54.407圣诞老人游戏41611:70B纹理: santaAndSleigh.6@2x.png 2013年-12-04:56:54.408圣诞老人游戏41611:70B纹理:SantaAndSleigh.8.ng 2013年-12-04 09:56:54.408圣诞老人游戏41611:70B纹理: santaAndSleigh.5@2x.png 2013年-12-04:56:54.408圣诞老人游戏41611:70B纹理:santaAndSleigh.4.ng 2013年-12-04: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:56:54.409圣诞老人游戏41611:70B纹理:santaAndSleigh.5.ng 2013年-12-04:56:54.410圣诞老人游戏41611:70B纹理: santaAndSleigh.1.png 2013年-12-04 09:56:54.410圣诞老人游戏41611:70B纹理: santaAndSleigh.3@2x.png 2013年-12-04:56:54.410圣诞老人游戏41611:70B纹理:SantaAndSleigh.6.ng 2013年-12-04 09:56:54.410圣诞老人游戏41611:70B纹理: santaAndSleigh.8@2x.png 2013年-12-04 09:56:54.411圣诞老人游戏41611:70B纹理: santaAndSleigh.2@2x.png 2013年-12-04:56:54.411圣诞老人游戏41611:70B纹理:SantaAndSleigh.2.ng 2013年-12-04 09:56:54.455圣诞老人游戏41611:70B纹理: santaAndSleigh.7@2x.png 2013年-12-04 09:56:54.456圣诞老人游戏41611:70B纹理: santaAndSleigh.1@2x.png 2013年-12-04:56:54.456圣诞老人游戏41611:70B纹理: santaAndSleigh.10.png 2013年-12-04 09:56:54.456圣诞老人游戏41611:70B纹理: santaAndSleigh.10@2x.png 2013年-12-04:56:54.457圣诞老人游戏41611:70B纹理: santaAndSleigh.7.png
谢谢!
发布于 2013-12-04 04:24:37
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中,则此方法可能无法工作。
发布于 2018-06-04 17:00:47
func getTexturesByAtlas(_ atlasName: String) -> [SKTexture] { let atlas = SKTextureAtlas(named: atlasName) return atlas.textureNames.sorted().map { name in atlas.textureNamed(name) } }
发布于 2014-01-23 18:52:05
您必须首先对textureNames数组进行排序。
SKTextureAtlas *sleighAtlas = [SKTextureAtlas atlasNamed:@"sleigh"];
NSArray * textureNames = [[atlas textureNames] sortedArrayUsingSelector: @selector(compare:)];
NSMutableArray *sleighTextures = [NSMutableArray new];
for (NSString *name in textureNames) {
[sleighTextures addObject: [sleighAtlas textureNamed: name]];
}https://stackoverflow.com/questions/20364314
复制相似问题