views:

813

answers:

4

I've read on few places already, that it's possible to combine XNA and WPF. What I personally need is a game/map editor, which would actually be the game itself (would have the engine running in background), because map system writes serialized versions of objects to XML, which are later loaded.

My problem is that I want an standard app, that'd run the engine in the background, and create game assets as user creates them from the frontend, and later on serialize them and put into XML.

This would also come in handy, if it's possible to run WPF from game, for UI, if anyone had any experiences with this, I'd appreciate if he/she'd share it.

Shortly: how can I make WPF (or winforms) app, that has XNA code running in one of it's control, and in background?

A: 

Have you tried creating a WPF application and then adding the XNA references to it?

You should be able to do that and then create a class that inherits from GameObject and put that into your WPF application.

WPF has direct access to a lot of DirectX as well as cameras and a lot of the things you'd need to just write the game in WPF. Maybe just use XNA methods for some of your calculations.

I can definitely see more than one way to skin this cat.

Eric
Uhh the engine is already half-way done, and I think I'll stick with it as it is, but I tought XNA needs some initialization, like Game1.cs file that ships with startup project. So how can I initialize WPF and XNA in one same project?
Johnny
If you haven't completely rewritten your game engine a dozen times, it's not even close to done :DIf you're looking for non-wpf content editor insipration, the Trials game in Xbox Live Arcade has a fantastic in-game track editor.Also, just because no one's put WPF controls into an XNA game doesn't mean it can't be done. WPF and XNA are classes just like anything else. I'd be skeptical to anyone that says you can't combine them however you want.
Eric
A: 

Check out this thread on the XNA forums: http://forums.xna.com/forums/p/1122/6455.aspx

It will 1) give you an idea of why this integration is so troublesome and 2) show you how to host an XNA control on a WPF form (look for ZMan's posts). As far as using WPF inside of XNA for GUI rendering, I wouldn't hold my breath. There is really very little reason for Microsoft to go out of its way to support this, and console GUI experiences son't really line up that well with an API meant for point and click.

Chris
+1  A: 

I don't know of anyone embedding WPF controls into an XNA game window. This would be a very difficult thing due to the fact that they both use DirectX for rendering. Since you're allowed to do anything with XNA, that would make WPF overlays and whatnot very difficult. If you're looking for in-game controls, try out NeoForce.

Going the other way is much simpler (read: actually supported). I know that you can embed an XNA window into a a Windows user control -- see this for a quick demo. I have used a technique similar to that to make an editor for my game. Unfortunately, integrating directly with WPF would be troublesome as well (due to the same reasons you can't put WPF controls in an XNA GameWindow). However, you could embed that control onto a WindowsFormsHost and that might work nicely (haven't ever tried it).

Obviously, this will not work on Xbox 360, since WinForms and WPF aren't available there, but you typically don't put your editor on 360 anyway.

ALSO: I hope you're not using XML serialization to load your game files at run time -- that's what the XNA Content Pipeline is for.

Travis Gockel
Nope, I have at least informed myself about basics of the tech I chose to work with. I've figured that XNA uses ContentPipeline, but when I add composition of multiple different **maps** then I really do need XML serialization, for later loading, of such contents, as they are required (not just game assets like images, textures, and such, but whole actual objects, with their specific settings, and etc.)
Johnny
Are you using custom content readers and writers for this? Also: does one of the solutions I offered work for you?
Travis Gockel
Well what I do, shortly is that I make the editor artificially create game objects (the game isn't actually running), just as a coder would do, and later on serialize them for saving. The game has the code for de-serializing that is supposed to recreate those objects, as they were inside the editor.Could this idea possibly work?BTW: +1 for pointing out what's possible, and what's not, and for the NeoForce (thought I knew about it before, but it's neat that you pointed it out too).
Johnny
My typical pipeline for assets is: Editor project creates the game objects and uses XML serialization to save them to a text file. Add those XML files to my content build project. When it comes time to build the game and assets, I have a custom content type importer and writer that process those XML into compressed binary assets. At game time, the binary files are read with a custom type reader. This gives you all the advantages of XML while editing and avoids the costly (in both time and space) XML serialization during play.
Travis Gockel
That's exactly what I wanna do, just I didn't have a thought about processing xml to binary assets, because I need it to become actual objects as I load the map, not just images and assets.Could my idea be achievable on your way?
Johnny
The short answer is yes, but I wrote a really long blog post in response to your question (as far as how to do it), since I can't express it in 600 characters. http://blog.gockelhut.com/2010/02/xml-serialization-xna-content-pipeline.html
Travis Gockel
XML serialization in XNA definitely has its place.http://msdn.microsoft.com/en-us/library/bb200105.aspx
Eric