5

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?

2
  • 1
    I think your trying to do something similar to what this person has done: youtube.com/watch?v=KRNI8NO9VNQ You can try to contact him about how he merged XNA and WPF.
    – zfedoran
    Commented Jan 30, 2010 at 16:42
  • Thanks for the link, looks awesome, I might contact him, tough I need something far less complex, and just for 2D environment.
    – Johnny
    Commented Jan 30, 2010 at 23:21

5 Answers 5

2

I posted this in another question, but there seem to be a lot of questions about how to integrate an XNA-like control in WPF. I read Nick Gravelyn's Blog and the Arcane.Xna post, and managed to develop something similar to both that completely parallels Microsoft.Xna.Framework.Game while providing WPF compatibility. You can even instantiate multiple Game classes, if you desire:

https://xnaml.codeplex.com/

1

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.

7
  • 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
    Commented Jan 29, 2010 at 23:06
  • Are you using custom content readers and writers for this? Also: does one of the solutions I offered work for you? Commented Jan 29, 2010 at 23:15
  • 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
    Commented Jan 29, 2010 at 23:22
  • 1
    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. Commented Jan 30, 2010 at 3:23
  • 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
    Commented Jan 30, 2010 at 15:12
0

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.

2
  • 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
    Commented Jan 29, 2010 at 22:10
  • If you haven't completely rewritten your game engine a dozen times, it's not even close to done :D If 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
    Commented Feb 3, 2010 at 1:33
0

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.

0

Here you go: http://iersoy.com/Posts.aspx?PostID=158


Source: How to embed flash into XNA on windows mobile

Not the answer you're looking for? Browse other questions tagged or ask your own question.