Jump to content
  • Advertisement
Sign in to follow this  
AnthonyDivitto

quick level editor question

This topic is 2498 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone,
i am still reasonably new to XNA so i decided to make a level editor for practice. I have a working editor but what i want to do is have a window that displays the tiles you can choose from like most other level editors have. Since I'm trying to learn the ins and outs of XNA i don't really want any code i can directly copy ( because I'm lazy and i will ). So my question is, what windows form would you use to display the tile sheet so that the user can select which tile he/she wants to draw with, and how would you go about using it. I hope this question is clear enough.

-thanks for any responses.

Share this post


Link to post
Share on other sites
Advertisement
I am assuming you are using the Winforms + XNA classes from Microsoft XNA Community.

What I've done in the past is derive a custom class from GraphicsDeviceControl to display the tiles. You can put that into a UserControl* if you like, and add a status bar/scrolling whatever you need.

You could use a windows form to display the tiles as bitmaps - but since you are already hooking into XNA, it is simpler to just use XNA for rendering the tiles. I've kept all my tile rendering code in a seperate assembly, and then I can use that from either the editor or the game, keeping things nicely seperated.

If you have a more specific question, I can try and answer that.

* Caveat when putting a GraphicsDeviceControl into a UserControl - the standard DesignMode check does not work, so you will have to handle that logic yourself. I've just always made a static IsProgramRunning property in the Program class and set it to True in the constructor.

Share this post


Link to post
Share on other sites
I was thinking of using a windows form, but your custom graphicsDevice idea seems more interesting. could you explain what you mean by custom graphicsDevice? i am unaware of how you would do this.

thanks for your response

Share this post


Link to post
Share on other sites
I was talking about a custom GraphicsDeviceControl class from here: http://create.msdn.c...nforms_series_1

I was assuming you are making an XNA game + editor, in which case the above classes are what you would need.

A GraphicsDeviceControl is just a Windows Form control which has an XNA surface to draw on. Typically you would derive your own special class for your tile selector, override the Draw method (and possibly Initialize), add whatever event handlers you need, and then you can draw/drop it onto a Form just like any other control.

Using straight Winforms without XNA is possible, of course, but if you are already tied into XNA (and in particular, using the same asset workflow etc), then it would be far simpler to use the above control class.

Share this post


Link to post
Share on other sites
I actually found this sample, and was doing some research on it. ( why i stopped posting until now ) I'm sure i'm starting to sound like a total noob but from what i have read that sample doesn't allow use of the game class. I looked through the sample and i can't seem to understand how it works with out it. I wish there was better documentation or a set tutorial that came with it.

I kept meaning to post this but forgot i have an xna project in a winForm using the example found here: http://royalexander.wordpress.com/2008/10/09/xna-30-and-winforms-the-easy-way/

It's basically a cheater way to get the same effect as the WinForm + XNA series you were talking about but it comes out sloppy and i dont like it. I would like to implement it the microsoft way because i know its been tested.

So how would i implement the code i already have ( written using the Game1 and varies other classes ) to work with the winform series example? i hope that makes since...

Share this post


Link to post
Share on other sites
I would recommend using the "official" methods from XNA creators - there are corner cases that these classes handle that others may not.

The 2 biggest things you are going to have to implement yourself (that the Game framework handles for you) are timing (e.g. for animation) and content loading. For timing, I believe there is an example provided with the above link that shows a hook into Idle event for calling Update() & Draw(). Also, you can read here for more detailed analysis: http://blogs.msdn.com/b/shawnhar/archive/2010/12/06/when-winforms-met-game-loop.aspx

Content gets a little harder. You can either use the winforms series 2 example to add content pipeline ti winforms, or handle loading resources yourself. The issue with using the pipeline in this manner is that the XNA developer kit (not just the runitmes) must be installed in order to run your application.

For this reason, I've always implemented my own asset loading. For textures only, it isn't difficult - it may get more complicated if you need 3d models, sounds, etc. in your editor.

Is there a specific piece of functionaility that you are unsure how to implement without the Game class? You could try posting some pieces of your code, it may help narrow down what issues you are having.

Share this post


Link to post
Share on other sites
I see, i'm not really having problems as much as i just wasn't sure how to implement the game class with the microsoft example. Your last post has cleared up most of my questions about how the framework is built. So for now i don't have any more questions, but if i run into another problem i'll be sure to post it up here. Thank you for your help. :)

Share this post


Link to post
Share on other sites
This is how I did mine. It's in SlimDX, but I used a picturebox to auto-size the tileset. Then I used GDI for the selector that gave me the position, when you mouse-over on the panel (slimDX) I use DX to draw the tile at the cursor position. When you click, it determines the X/Y position and the size of the object and puts it down. Good luck.

[attachment=7211:Untitled.png]

Share this post


Link to post
Share on other sites
I've been looking over the winForm series 1 example thing and maybe this stuff is over my head but i don't really understand how it works at all. I understand that i need a windows form with an XNA window built into it. I also understand that i have to monitor the time which isn't a big deal since there is no animations in a level editor. I'll tackle content loading when i get there but can someone really break down what [post='this']http://create.msdn.com/en-US/education/catalog/sample/winforms_series_1[/post] is doing and how/why it is working? I know i could write my own version of it if i understood how it worked.. maybe I'm just thinking to hard.. lol

Share this post


Link to post
Share on other sites

I'll tackle content loading when i get there but can someone really break down what [post='this']http://create.msdn.c...nforms_series_1[/post] is doing and how/why it is working?


Look at "SpriteFontControl.cs" for the most basic use case.

This class overrides the provided "GraphicsDeviceControl", much like you would override the Game class. Then it just provides initialization and drawing code, and you have a (simple) XNA control you can drag & drop onto a form.

I would start by just creating a new Windows Forms application, and copy over GraphicsDeviceControl, GraphicsDeviceContainer, and ServiceContainer to your project. These three classes work together, and are all you should need from the example. Subclass GraphicsDeviceControl, as above, and try just loading an image from disk (using Texture2D.FromStream() or whatever it's called), and SpriteBatch to the window. You will have to create your own SpriteBatch as in the example. After an initial build, you should be able to drag&drop the control over to your form.

If you can get this far without trouble, that's basically all there is to it, the rest is specific to either Winforms or XNA.

EDIT: basically, the GraphicsDeviceControl (and it's two helper classes) is a WForms control that gives you an XNA GraphicsDevice. The rest of the code in those classes is to keep everything working behind the scenes, and isn't really necessary to understand.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!