开发者

What is the "advised" way to load external data into an XNA4.0 Game?

I am currently working on a game destined to be submitted to the XBLIG.

My question is quite simple, I was wondering which is the "advised" way to load data via an external XML file.

I need this at least for develpment (on PC) so that the Game Designer can faff about with the gameplay variables without needing to rebuild.

In xna3.1 I used the IntermediateSerializer which no longer exists for xna4.0开发者_Go百科.

I'm probably going to create a content pipeline extension for shipping, unless of course someone can propose an amazing answer that works on both PC and XBox! :D

Thanks,


Well, first of all, IntermediateSerializer does exist in XNA 4.0!

However, XNA 4.0 changed from targeting the .NET 2.0 framework to targeting the .NET 4.0 framework, which comes in two flavours. The XNA runtime assemblies target the compact framework, but the Content Pipeline assemblies target the full framework. You will need to go into your project properties and change the target framework to allow you to use IntermediateSerializer.

In addition, the Content Pipeline is not available on Xbox 360, and neither is it available on Windows without the full XNA Game Studio installed. Which means you can't use InterpediateSerializer when running on Xbox 360 or for distribution on Windows (applies to both XNA 3.1 and 4.0).

So if you want to use it at runtime, during development, the solution is to add a specific build target for development on Windows to your project. Give it a pre-processor definition for #ifdef DEVELOPMENT to wrap your code in, make target the (much bulkier) full .NET 4.0 Framework, and add an assembly reference to Microsoft.Xna.Framework.Content.Pipeline (where IntermediateSerializer lives).

(I will leave figuring out conditional framework targeting and assembly referencing as something for you to research - I'm pretty sure it requires hand-editing the project file. Or you could just create and maintain a new project file in parallel.)

So all that leaves is the question of what to do in your distribution versions, where you don't have IntermediateSerializer?

That is extremely easy: You can drag your XML file into your content project. The default Content Pipeline XML importer takes your XML, runs it through IntermediateSerializer for you, creating an XNB file. You can then load that file as content at runtime, via the ContentManager. (see also)

(Rather than sticking a bunch of conditionals in your loading code, I recommend using this method normally (at load time), and then only using the IntermediateSerializer method for your "reload the XML" code path.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜