问题描述
我有一个可以使用以下扩展名从iOS 8中的.sks文件很好地加载的应用程序:
I have an app which loads nicely from an .sks file in iOS 8 using the following extension:
class func unarchiveFromFile(file : NSString) -> SKNode?
{
if let path = NSBundle.mainBundle().pathForResource(file as String, ofType: "sks")
{
var sceneData = NSData(contentsOfFile: path, options: .DataReadingMappedIfSafe, error: nil)!
var archiver = NSKeyedUnarchiver(forReadingWithData: sceneData)
archiver.setClass(self.classForKeyedUnarchiver(), forClassName: "SKScene")
let scene = archiver.decodeObjectForKey(NSKeyedArchiveRootObjectKey) as! GameScene
archiver.finishDecoding()
return scene
}
else
{
return nil
}
}
但是,当我将其与运行iOS 7.1的设备一起使用时,我在AppDelegate上获得了EXC_BAD_ACCESS代码EXC_I386_GPFLT,并在日志中获得了此代码:
However, when I use this with devices running iOS 7.1, I get a EXC_BAD_ACCESS code EXC_I386_GPFLT on the AppDelegate and this in the log:
SKTexture:加载图像资源:"MissingResource.png"时出错
SKTexture: Error loading image resource: "MissingResource.png"
我认为问题可能在于sks文件未正确加载.谁能告诉我如何从sks文件加载场景?
I believe the issue may be the sks file being improperly loaded. Could anyone tell me how I can load my scene from the sks file?
感谢您的帮助,
推荐答案
有趣的是,我设法通过检查iOS 8之前的版本是否正在运行来解决此问题.如果是这样,我将加载游戏场景,然后将其复制.这可以通过某种方式解决该问题:
Interestingly I managed to solve this issue by checking whether pre-iOS 8 was running. If so, I would load the game scene and then copy it. This solves the issue somehow:
let tempScene = GameScene.unarchiveFromFile(gameSceneFile) as? GameScene
scene = tempScene!.copy() as! GameScene
这篇关于在iOS 7.1的Swift中取消存档.sks文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!