Ios 如何组织Sprite工具包的纹理图谱

Ios 如何组织Sprite工具包的纹理图谱,ios,swift,textures,sprite-kit,Ios,Swift,Textures,Sprite Kit,好吧,我已经做了几个小时了,我真的很困惑。我的后台类代码如下: class Background : SKNode { required init(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } override init() { super.init() buildBackground() }

好吧,我已经做了几个小时了,我真的很困惑。我的后台类代码如下:

class Background : SKNode {

    required init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    override init() {
        super.init()
        buildBackground()
    }


    func buildBackground() {
        var sprite : SKSpriteNode = SKSpriteNode(imageNamed: "background_full")

        sprite.anchorPoint = CGPointZero
        self.addChild(sprite)
    }

}
我现在还有以下atlas文件,指向其中的png文件

background@2x~iphone.atlas --> background.png, background-567h.png, background-667h.png
background@3x~iphone.atlas --> background.png
background~ipad.atlas --> background.png
background@2x~ipad.atlas --> background.png
我得到了不可预测的、非理性的、随机的结果,在iOS 7上可能找不到iPhone4S的图像,但在iOS 8上却很好(不过使用了iPhone5的图像)。iphone5将使用iPad@1x的纹理等等

我原来是跟在后面的 但我不明白出了什么问题

注意:@3x给了我一个错误,但我明白为什么,这个文件太大了,无法包含在地图册中,我计划在基本工作完成后分割背景。所以你可以忽略@3x,因为我还没有把它包括在我的项目中,我只是想给你完整的图片

编辑-注意我正在iOS 7.03、7.1和8.0上测试 我已经把我的调查缩减到

background.atlas --> background.png (iPad 2)
background@2x.atlas --> background.png (iPhone 4s)
iPad2显示了正确的结果,但是,它的纹理被用于iPhone4S

如果,我有如下设置:

background@2x~iphone.atlas --> background.png (iPhone 4s)
background~ipad.atlas --> background.png (iPad 2)
background.atlas --> background~ipad.png (iPad 2)
background@2x.atlas --> background@2x~iphone.png (iPhone 4s)
iPhone4S显示了正确的结果,但是,它的纹理被用于iPad2,对于这两款设备,我在iOS 8.0上都得到了一个错误,显示了模拟器设备中应用程序的路径,说“SKTexture无法加载图像资源”/background@2x~iphone.atlasc/background@2x~iphone.1.png“'

对于以上两种情况,atlas中最先出现的纹理似乎是默认使用的纹理

如果,我有如下设置:

background@2x~iphone.atlas --> background.png (iPhone 4s)
background~ipad.atlas --> background.png (iPad 2)
background.atlas --> background~ipad.png (iPad 2)
background@2x.atlas --> background@2x~iphone.png (iPhone 4s)
然后一切正常,除了在iOS 7.03上,我得到一个错误,说“SKTexture无法加载图像资源”background.png“,就是这样,没有前面示例中的长路径

另一次编辑 最后一点告诉我,如果我将所有设备中的所有背景PNG文件集中到一个atlas中,SpriteKit将分离到适当的设备中,因此正确的纹理将加载到内存中。但是,我必须区分所有的iPhone型号(特别是声明为@2x的iPhone 5和6)。如果我把一个设备的相关PNG文件都放在一起,我说的对吗


如果没有,我决定将PNG分离到它们自己的设备图集中,并编写一些代码来区分和加载正确的图集。

创建一个文件夹。图集然后将所有图像添加到该文件夹中,例如,确保使用正确的命名约定

rocky~ipad.png
rocky@2x~ipad.png
rocky@2x~iphone.png
drago~ipad.png
drago@2x~ipad.png
drago@2x~iphone.png
然后,将folder.atlas添加到项目中,并进行xcode构建

在xcode中的products文件夹中搜索.app捆绑包,右键单击选择show in finder,然后右键单击捆绑包并选择show contents of the package,在那里可以找到folder.atlasc和folder.1~ipad.png,
文件夹。1@2x~ipad.png
文件夹。1@2x~iphone.png
,每个地图集都有相应的大小和一个.plist文件,其中包含对它们的引用

另外请注意,atlas文件中的“.1”用于计算地图集,因为当图像大于atlas允许的大小时,xcode将生成更多地图集,并按照该约定进行计数

无需担心大问题

如果需要,请检查此项


不可预测的结果?执行产品->清除并从设备/模拟器中删除应用程序,然后重试。Xcode不会从已部署的捆绑包中删除现有文件,这可能会导致一台设备能够加载一个纹理,而另一台设备无法加载或退回到另一个纹理。我已确保在每次运行时清理并删除该应用程序。我还为原始帖子添加了一个编辑。我会进一步调查的。在为不同设备命名atlas时,是否有默认或推荐的格式?我找不到苹果的。