Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I want to create various sprite tool and map editor using XNA. Now, the problem is I do not know how would I implement the window forms and components (such as button, check box, sprite list, etc.) into my program and allow it to completely control my XNA environment. If there is any tutorials or examples that show how to make editor for XNA, then I would be very pleasing.

Thanks

share|improve this question
    
Even though i always created my own editors, i mostly ended at that, with kind of complete editor and no energy for game :) So i would advise you to try use already created editors mapeditor.org and brashmonkey.com if you aim to complete game :) –  Kikaimaru May 3 '12 at 17:16
    
If it's possible, can you tell me how you build the editor yourself? Do you integrate .NET framework with the XNA framework? I am just curious to know that, because I have never build one before. –  user1542 May 4 '12 at 3:51
add comment

2 Answers

up vote 1 down vote accepted

I have done several editors... and the easier is using c# winform... it provides you with buttons, panels, listbox...

Of course, you can integrate it in a panel, like proposes @milkboat, but I think that winform series is not a good example.. because the xna code part is not driven as usual, there is no game class, and the code becomes ugly...

I prefer use this code, http://pastebin.com/kkkmKm8n, is not mine, but I've modified it to add the interface and the CreateAndShow method.

This way your game will not suffer many modifications among using the editor or not using it.

You only have to inherit your game class from XnaControlGame, and the editor form that will host the xna control should implement IXnaFormContainer.

I think is easy and more elegant than other approachs.... because let you difference xna part from the winform part

An editor with this approach:

http://www.youtube.com/watch?v=0wiuhZeq1cs&feature=plcp

An editor with a simple form approach, when the form is visible is editor mode, when dissapears is game mode.

http://www.youtube.com/watch?v=4QDeY15Ox-g

share|improve this answer
    
I do wish people would stop using, posting and endorsing these awful hacks for XNA + WinForms. Please use the official sample‌​. It is far better to write the simple code required to add what you need to the official sample, than it is to go around hacking together Game and Form. –  Andrew Russell Aug 1 '12 at 7:57
    
my hack its not awful... :) lets the official sample use the Microsoft.Xna.Framework.Game class? NO.. my awful hack does and I can share components and code among editor and game... it is simpler... otherwise everyone is free of using it or not....;) –  Blau Aug 1 '12 at 8:49
    
Yes it is awful. And it's especially annoying when other people see code like this (it's not just yours) promoted as being "right" and then run into problems with it. Game is an optional helper class in XNA! If you want functionality like it - please do it properly and implement your own class with Services, Content, Draw, Update, etc. It's not hard! Steal the internals from ExEn if you like. But don't try and bend XNA's Game class into doing something it is not designed to do! –  Andrew Russell Aug 1 '12 at 12:13
    
xna itself it's not designed to work in a winform... so don't bother, using the winform sample or this is not so crucial... –  Blau Aug 1 '12 at 13:26
    
The core XNA library (everything except microsoft.xna.framework.game.dll) is completely independent. All you need to provide is a PresentationParameters.DeviceWindowHandle that XNA (internally, DirectX) can use to create a graphics device. You can use anything that will give you a window handle - WinForms, Qt, wxWidgets. You could use Win32 if you wanted! The Game class provides a convenient default implementation. The WinForms sample provides another - it's open source and designed for the purpose. You are shoving a handle into Game's private constructor and hoping for the best! –  Andrew Russell Aug 1 '12 at 13:51
show 2 more comments

http://create.msdn.com/en-US/education/catalog/sample/winforms_series_1

This example from the XNA site shows you how to implement a xna device into a windows forms project.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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