Rather than using Game.Run, I need to manually handle the game loop. Sort of like this equivalent scenario using winforms:
someForm.Show();
while(someForm.Created)
{
//Insert rendering stuff here
Application.DoEvents();
}
So, how would I use Game.Tick() to accomplish the same thing I see that there's a Game.IsActive property, but it returns false when I try the following:
while(myGame.IsActive)
{
//Insert rendering stuff here
myGame.Tick();
}
This of course exits immediately. I assume I need to get the game active before calling Tick; can I do that without Game.Run()

Game.Tick
WV John
Andrew Mercer
As it is, Game.IsActive is based on the "activeness" (is that a word ) of the window that the Game created for you. The window is shown as part of calling Game.Run which activates the windows/app/game.
Embedding a Game in a Windows Forms application is not a scenario that the XNA application model is designed for. The lower-level classes in the XNA Framework can be used within a WinForms app (i.e. GraphicsDevice, etc...) but not Game or GameComponents.
If the "embedding in WinForms" scenario is important to you (or anyone else here) please file a bug via Connect (or vote on a bug that is there) so we can review this plan appropriately.
Thanks,
Paul
abuja
A few reasons
1) the choice should be there, as all scenarios are not alike. There are situations where having absolute control over when a frame is rendered is a good thing (like, only render when the user presses a button, for example). Popular graphics engines such as Ogre provide the ability to choose between it managing the render loop, or handling it yourself. Users shouldn't be forced to stick to one method.
2) Clearly the means of telling XNA to render a single frame is already there, as exemplified by Game.Tick(), which calls Game.Update and Game.Draw. There's also the means to tell whether the game is active. So it seems odd that there isn't also a way to activate the game without it entering it's own rendering loop.
3) I'm hoping that by manually managing the rendering loop, I can avoid having to create a second process. In my particular example I have a winforms dialog where you select a demo, but the winform and XNA messaging loops can't coexist in the same thread. This will also be a problem for people who wish to make some sort of editor with XNA rendering inside a winforms application.
Michael Weed
>I need to manually handle the game loop.
Why
Yes I know thats not the question you asked but the XNA team have spent a lot of time making a game loop that works just fine and hopefully this will avoid the billions of hours wasted in managed directx with people debating render loops. I suspect this is one of the reasons there are few MDX games :-)
If you are worried about starving the CPU them the game object has ways to limit that. Just like a winforms app - using the event is pretty much the way to go here in all but a few scenarios.
Chiranjeevi Undavalli
Well as the scope of the XNA Framework seems to be so narrow, I hope the XNA team is looking into that to make things like embedding into Forms applications easier - I read somewhere you are looking for further use for XNA to take that into consideration. And as managed DirectX 2 wont be released anymore and will be part of XNA there must be some kind of option to use the framework in Forms, e.g. for scenarios like described above or simply windows applications which are in need of 3D. Just pointing to managed DirectX 1 with all the flaws it has when running under .Net 2 is not enough, especially as it wont be developed further.
But that Game.Run opens a new window is the only nasty thing I discovered yet. I wrote a new class implemening IGraphicsDeviceService which takes a control handle for creating the device. So running XNA inside a forms application does not seem to be a big problem, BUT because Run is not called some of the initialization is not called, either. It would be great if you would make the "Start"/"Initialize" method(s) which Run calls (and which ost likely raise the OnStarting event) public. I helped myself out by creating this little Start method wich I call after initializing the game components and before rendering the first time:
protected void Start(){
this.GameServices.AddService(typeof(IGraphicsDeviceService), this.graphics);
foreach (GameComponent gameComponent in this.GameComponents)
gameComponent.Start();
}
That serves my current purpose to initialize and startup the Framework inside myfForms application, but I am pretty sure there must be a little bit more code ;)
jenx222
Anyways, I managed to implement the beginnings of an XNA rendersystem in my graphics engine. As it is, the user has a choice between an automatic rendering loop or a manual one with opengl and directx, but are limited to automatic with xna.
Thanks guys.
Daikoku