我在使用多个图集时遇到了问题。SKTextureAtlas:不止一个图集混淆
例如我有main_menu.atlas和game.atlas与这些场景的图像。在主菜单场景出现之前,我为它准备了图集([SKTextureAtlas atlasNamed:@“main_menu”]),并且所有的工作都很好。但是当我开始一个游戏并且在游戏中准备游戏地图集([SKTextureAtlas atlasNamed:@“game”])之后,我只看到空的节点(带红色交叉的矩形)。没有任何豁免或警告 - 一切正常。
当我将所有游戏资产移动到main_menu.atlas并删除game.atlas时,所有工作都正常 - 我在游戏中看到精灵。但我想分开地图集来优化性能。
我使用我自己的助手进行SpriteKit纹理管理。它加载地图集并返回我需要的纹理。所以我有这些方法:
- (void) loadTexturesWithName:(NSString*)name {
name = [[self currentDeviceString] stringByAppendingString:[NSString stringWithFormat:@"_%@", name]];
SKTextureAtlas *atlas = [SKTextureAtlas atlasNamed:name];
[self.dictAtlases setObject:atlas forKey:name];
}
- (SKTexture *) textureWithName:(NSString*)string {
string = [string stringByAppendingString:@".png"];
SKTexture *texture;
SKTextureAtlas *atlas;
for (NSString *key in self.dictAtlases) {
atlas = [self.dictAtlases objectForKey:key];
texture = [atlas textureNamed:string];
if(texture) {
return texture;
}
}
return nil; // never returns "nil" in my cases
}
“干净”没有帮助。 我做了什么错? 在此先感谢。
我敢肯定,你只能有一个纹理地图集和sprite工具包,这通常是动态创建的:https://developer.apple.com/library /ios/recipes/xcode_help-texture_atlas/AboutTextureAtlases/AboutTextureAtlases.html – GuybrushThreepwood
谢谢。但是,例如,如果我有两个精灵应该出现在一个场景中,但第一个存储在〜iphone.1.png,第二个存储在〜iphone.2.png(另一个精灵表),这两个精灵表必须是在内存和绘制调用计数会增加?如果两个精灵都在一个精灵表中,我认为会更好,但是链接提供的方法不会保证这一点。 –
我不认为你有任何选择 - 它会发现精灵没有问题。解决这个问题的方法是将所有单个的精灵放入链接中概述的项目中,并让SpriteKit构建地图集。据我所见,Sprite Kit不适用于预先提供的图集。如果你需要这个,你可能想看看Cocos2d或OpenGLES解决方案。 – GuybrushThreepwood