在哪里可以找到 Objective C 的通用游戏状态单例?
我想在 NSCoder 中使用和存储游戏状态单例,但我发现很难找到使用 NSKeyedArchiver/NSCoder 例程保存和加载其数据的通用状态管理。
我想知道是否有人可以指导我一个好的教程,或者用作游戏状态单例的通用代码,并在 NSCoder 中保存/加载?
谢谢
I'm wanting to use, and store a game state singleton inside NSCoder, but I am finding it quite difficult to find a generic state management that saves and loads its data using the NSKeyedArchiver/NSCoder routines.
I'm wondering if someone can direct me to a good tutorial, or generic code for use as a game state singleton, with it saving/loading in NSCoder?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经能够通过观看 71squared.com 的教程来获得基本的游戏状态管理器工作,
我使用 CocoaWithLove 的 SynthesizeSingleton.h,并且能够使用 NSCoder / 归档保存和加载状态。
由于它使用单例,我可以通过编写来引用它:
GameStateManager *gsm = [GameStateManager sharedGameStateManager];
如下所示:
在我的 Player.h/.m 文件中,我这样做:
// ---
我的后续问题是:
1)我是否打算将
listOfPlayers
放入 GameStateManager 中?-->转移到一个新问题
2)在我的编码器中,我必须单独存储每个字段,是否不可能只存储实际对象本身?
3)一个对象的编码是否也会对其所有子对象进行编码?
假设我有一个父类(玩家)和一个子类(武器)。如果我只对玩家对象进行编码,它是否会自动对所有武器进行编码,因为它们是链接的?
谢谢。
I've been able to get a basic game state manager working from watching tutorials from 71squared.com
I use the SynthesizeSingleton.h from CocoaWithLove and am able to save and load states using NSCoder / archiving.
As it uses the singelton, I can reference it by writing:
GameStateManager *gsm = [GameStateManager sharedGameStateManager];
As below:
In my Player.h/.m file I do this:
// ---
My follow-up questions are:
1) Am I meant to put a
listOfPlayers
in the GameStateManager?--> Moved to a new question
2) In my encoder, I have to store each field individually, is it not possible to just store the actual object itself?
3) Does encoding of an object also encode all its children?
Lets say I have a Parent class (Player) and a Child class (Weapons). If I encode the Player object only, will it encode all the Weapons too automatically because they are linked?
Thanks.