XNA - WP7 - TiledLib - 序列化和逻辑删除
我目前正在使用适用于 Windows Phone 7 的 XNA Game Studio 4.0 框架编写 2D 游戏。我已经到了这样的阶段:如果用户想要保存/加载或恢复,我正在解决游戏的墓碑问题比赛稍后进行。
我目前正在使用 TiledLib 库来渲染地图等以及 屏幕状态管理示例作为我的项目的基础(例如,正确的墓碑事件都是到位)。 TiledLib 库中的 Map
对象具有一个多维数组 ([,]
),用于存储每个 TileLayer
内的地图图块。我的地图只有一个 TileLayer
,并且只有 1 个 Texture2D
,根据图块显示的内容具有不同的 Rectangle
源位置。重要的是,我要跟踪每个图块的所有适当的源矩形,以便已编辑的地图可以按照玩家离开的方式恢复。
我在尝试找出实现游戏屏幕墓碑的最佳方法(或任何方法)时遇到了很多麻烦。我在序列化方面没有太多经验,这是我第一次尝试为 Windows Phone 7 应用程序进行逻辑删除。我知道非锯齿状数组无法使用通常的 XmlSerializer 进行序列化,有没有办法解决这个问题?自定义序列化器是一个好的选择吗?优点/缺点?还有人有使用 TileLib 和序列化游戏屏幕的经验吗?或者带有 X、Y 坐标的 2D 地图?多少数据对于逻辑删除来说是太多数据而无法序列化?
预先感谢您的回答和建议。
I am currently writing a 2D game using the XNA Game Studio 4.0 framework for Windows Phone 7. I have gotten to the stage where I am tackling the problem of tomb-stoning the game if the user would like to save/load or if they resume the game at a later point.
I'm currently using the TiledLib library for the rendering etc of the map and also the screen state management example as a basis for my project (eg the events for tombstoning correctly are all in place). The Map
object in the TiledLib library has a multidimensional array ([,]
) to store the tiles of the map within each TileLayer
. My map only has one TileLayer
, and only 1 Texture2D
with different Rectangle
source locations base on what the tile is displaying. It is important that I track all of the appropriate source rectangles for each tile so the map that has been edited can be resumed the way the player left it.
I'm having quite a lot of trouble trying to work out the best way (or any way) to achieve tombstoning for the game screen. I have not had much experience with serialization and this is my first attempt at tombstoning for a Windows Phone 7 application. I understand that non-jagged arrays can not be serialized using the usual XmlSerializer, is there a method to get around this? Is a custom serializer a good path to go down? Pros/Cons? Has any one else had experience with TileLib and serializing a game screen? Or a 2D map with an X,Y coordinates? How much data is too much data to serialize for tombstoning?
Thanks in advance for answers and advice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议您使用
BinaryReader
和BinaryWriter
编写自己的序列化例程,因为您可以序列化完全任意的数据,并完全控制该过程,并使用 比自动 XML 序列化速度快得多。当然,缺点是您必须使读写例程彼此保持同步,并与您正在序列化的类保持同步。此外,如果您的代码发生更改(添加或删除要序列化的数据),您还需要一种机制来处理序列化格式的更改。
I would recommend writing your own serialization routines using
BinaryReader
andBinaryWriter
, on the basis that you can serialize completely arbitrary data, with full control over the process, and with considerably more speed than automatic XML serialization.The downside, of course, is that you must keep your read and write routines in sync with one another, and with the classes you are serializing. Also you will need a mechanism for handling changes in your serialization format, if your code changes (you add or remove data to serialize).