存储精灵套件等级数据 [英] Storing Sprite Kit Level Data

查看:33
本文介绍了存储精灵套件等级数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个项目,其中一组目标出现在屏幕上.目标应同时出现一定数量,并且每次出现之间应有一定的延迟.我的问题是如何正确存储此游戏的关卡数据.我当时正在考虑使用csv文件存储级别数据(目标类型,位置,延迟等),但是我想知道是否有更好的方法来做到这一点.我还考虑过制作一个关卡对象来存储关卡信息,但是我不确定.苹果公司说要使用精灵节点档案",但我似乎无法弄清楚这是什么意思.有什么想法吗?

There is a project I am working on in which a set of targets appear onto the screen. The targets should appear a certain amount at the same time, and with a certain delay in between each appearance. My question is how I would correctly store the level data for this game. I was considering using a csv file to store the level data (target type, location, delay, etc.), but I'm wondering if there is a better way to do it. I had also considered making a level object to store level information, but I'm not sure. Apple says to use 'Archives of sprite nodes', but I can't seem to find out what that means. Any thoughts?

推荐答案

您是否考虑过使用plist文件呢?那将是最容易解析的.您可以有一系列目标(词典),然后定义位置,绝对延迟以及您想要的其他任何东西.

Did you think about using a plist file instead? That would be the easiest to parse. You could have an array of targets (dictionarys) and then define position, absolute delay and what ever else you want.

然后将其读入数组:

NSArray *targets = [NSArray arrayWithContentsOfFile:plistPath];
for (NSDictionary *dictionary in targets) {
    CGPoint position = CGPointMake([dictionary[@"positionX"] floatValue], 
                                   [dictionary[@"positionY"] floatValue]);
    float delay = [dictionary[@"time"] floatValue];
    // Do something with this information, maybe create a Target instance etc.
}

您也可以对CSV文件执行相同的操作,但是解析起来会有些困难(虽然不太难).

You could also do the same with CSV files, but they would be a little bit more difficult to parse (not too difficult though).

关于档案,Apple的意思是所有Sprite Kit类都支持NSCoding.这意味着可以将它们存档到文件(或NSData对象)中,然后再从该存档中取消存档.但是,这与您要执行的操作不同.存档将创建游戏当前状态的单个快照".因此,例如在用户离开时保存游戏就很好了.

Regarding archives, what Apple means is that all Sprite Kit classes support NSCoding. That means they can be archived into a file (or NSData object) and later unarchived from that archive. This is however different from what you want to do. Archiving would create a single "snapshot" of the current state of the game. So this would be nice to save the game for instance when the user leaves.

这篇关于存储精灵套件等级数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆