swift - 如何在 SpriteKit 游戏中保存游戏进度

标签 swift sprite-kit

我目前正在使用 SpriteKit、GameplayKit 和 JSTileMap 开发游戏。我正在尝试实现一个功能来保存游戏进度。我尝试使用 NSCoder 对每个类中的所有变量进行编码/解码,但 XCode 告诉我所有使用 Entity 和 Component 的类都不符合 NSCoding。那么如何保存我的游戏数据呢?我可以只对主要游戏场景中的所有内容进行编码吗?

感谢您的帮助。

最佳答案

确保你正确地遵守了 NSCoding 协议(protocol),应该看起来像这样

class Entity : GKEntity,NSCoding
{
    func encodeWithCoder(aCoder: NSCoder)
    {

    }
    required init?(coder aDecoder: NSCoder)
    {

    }
}

class Component : GKComponent,NSCoding
{
    func encodeWithCoder(aCoder: NSCoder)
    {

    }
    required init?(coder aDecoder: NSCoder)
    {

    }
}

关于swift - 如何在 SpriteKit 游戏中保存游戏进度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35135627/

相关文章:

ios - 如何在绘制多个 UIImage 时优化 CGContext 内存消耗?

ios - 快速跳过登录 Controller

xcode - Xcode控制台中的 "Some"关键字是什么意思?

ios - AWS Mobile Hub - 如何在没有 Storyboard 的情况下实现用户登录

ios - 单独的触摸代码

ios - SpriteKit 不尊重 zPosition?

swift - 使用 NSUser Defaults 保存当前游戏分数(不是高分)?

ios - SpriteKit 液体(水)

ios - 我可以在没有 SKAction 的情况下在屏幕上移动节点吗?

ios - UITableView、registerClass 和 detailTextLabel——奇怪的行为