1
\$\begingroup\$

I have a game in XNA, I want to connect this game with WindowForm to show for example the distance and the position.

I tried to apply many tutorials that talking about this. but here is my problem :

My Problem

It's empty!! How can I show my game.

I think my problem is here :

using Microsoft.Xna.Framework;

namespace MissileProject.CustomForms
{
    public class MissileDisplay : WinFormsGraphicsDevice.GraphicsDeviceControl
    {
        protected override void Initialize()
        {

        }

        protected override void Draw()
        {
           GraphicsDevice.Clear(Color.CornflowerBlue);
        }
    }
}

Any help or advice please ?

\$\endgroup\$
1
  • 1
    \$\begingroup\$ Do you have more code for the MissleDisplay? The only drawing code that is happening here is clearing the screeen with the Cornflower Blue color, which is exactly what your screenshot is showing. If you have your game code in a separate project, you'll need to copy across most of it, and merge it into the MissleDisplay control in order for your game to show. \$\endgroup\$
    – Seta
    Dec 14 '14 at 17:24
1
\$\begingroup\$

Put simply, you only have the bare bones of a WinForms XNA based game. Your going to have to port your games code across from your XNA game project into your WinForms project. You'll have to create the MainLoop, and use it to call your MissileDisplay's Update and Invalidate Methods to simulate XNA's Update, and to call the GraphicsDeviceControl's Draw methods

If you need help with this, I found this 5 step guide very helpful. I was able to get 4 different displays for a proto level editor running at the same time.

\$\endgroup\$
1
\$\begingroup\$

Based on your code, I can tell you're using the example that Microsoft provides for linking WinForms to XNA (for others: part one, part two).

I would say to look at the provided control that displays the spinning triangle. Specifically this bit:

protected override void Initialize()
{
    // ...
    // Hook the idle event to constantly redraw our animation.
    Application.Idle += delegate { Invalidate(); };
}

This allows you to leverage the fact that events are not constantly being triggered in WinForms and will draw your game whenever those events are not being handled (just like you would normally do in a C++ application).

As you can tell from the example, you will also need to handle time by yourself using a Stopwatch. You can probably hack together a small GameTime class for yourself if you want and incorporate it.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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