好吧,我已经花了好几个小时了,我真的很困惑。我的后台类代码如下:
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)
}
}我现在还有以下地图集文件,指向其中的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上可能找不到iPhone 4s的图像,但在iOS 8上完全可以(但是使用了为iPhone 5准备的图像)。iPhone 5将为iPad @1x使用纹理,以此类推。
我最初关注的是the solution for this post,但我就是不明白哪里出了问题。
注意:@3x给了我一个错误,但我理解为什么,文件太大而不能包含在地图集中,我计划在我得到基本的工作后划分背景。所以你可以忽略@3x,因为我没有把它包含在我的项目中,我只是想给你一个完整的描述。
编辑-注意:我正在iOS 7.03、7.1和8.0上测试
我已经把我的调查减少到
background.atlas --> background.png (iPad 2)
background@2x.atlas --> background.png (iPhone 4s)iPad 2显示了正确的结果,但其纹理用于iPhone 4s。
如果我有这样的设置:
background@2x~iphone.atlas --> background.png (iPhone 4s)
background~ipad.atlas --> background.png (iPad 2)iPhone 4s显示了正确的结果,但是,它的纹理正在用于iPad 2,并且对于这两个设备,我在iOS 8.0上都得到了一个错误,显示了模拟器设备中应用程序的路径,并显示了“SKTexture无法加载图像资源".../background@2x~iphone.atlasc/background@2x~iphone.1.png”“。
对于以上两种情况,似乎地图集中最先出现的纹理是默认使用的纹理
如果我有这样的设置:
background.atlas --> background~ipad.png (iPad 2)
background@2x.atlas --> background@2x~iphone.png (iPhone 4s)然后一切都会正常工作,除了在iOS 7.03中,我得到一个错误提示'SKTexture无法加载图像资源"background.png“,就是这样,没有像上一个例子中那样的长路径
另一个编辑
bottom of this page上的最后一个要点告诉我,如果我将所有设备的所有背景PNG文件捆绑到一个地图集中,SpriteKit将分离到适当的设备中,因此正确的纹理将加载到内存中。但是,我将不得不区分所有的iPhone型号(特别是iPhone5和iPhone6,它们被声明为@2x)。如果我把设备的相关PNG文件捆绑在一起,就会加载它们,这样说对吗?
如果没有,我决定将PNG分离到它们自己的设备图集中,并编写一些代码来区分和加载正确的图集。
发布于 2014-12-28 07:45:36
创建一个folder.atlas,然后将所有图像添加到该文件夹中,请确保使用正确的命名约定,例如
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 content of the package,您将在那里找到folder.atlasc和里面的folder.1~ipad.png、folder.1@2x~ipad.png和folder.1@2x~iphone.png,每个地图集都有相应的大小,还有一个带有它们的引用的.plist文件。
还请注意,地图集文件中的".1“是计算地图集的,因为当图像大于地图集允许的大小时,xcode会生成更多的地图集,并按照约定计算它们。
担心不是为了更大。
如果需要,请检查此link
thanks.https://stackoverflow.com/questions/25818521
复制相似问题