• Advertisement
Sign in to follow this  

Game Loop Not Repainting

This topic is 1779 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

Ok, this is as basic as it gets.  I'm just trying to write a simple game, but I'm not suing XNA or any other game library for it at the moment.  I'm simply trying to do the following:

 

At the end of the constructor:

 

while (gameState != EXITING)
            {
                update();
            }

 

In update:

 

if (DateTime.Now - lastUpdate >= updateFreq)
            {

 

/...process

                this.Refresh();
                Application.DoEvents();
                lastUpdate = DateTime.Now;

                while (DateTime.Now - lastUpdate >= updateFreq) {}

            }

 

And I override OnPaint.

 

 

It calls all of the logic, but never gets to OnPaint...   So what am I screwing up?

 

 

Share this post


Link to post
Share on other sites
Advertisement

This is in a c# WinForm, by the way.  I know that's not the best framework for a game, but I was just trying to do something quickly.  I might just scrap it and re-design what I can for XNA, since it makes all of the timing junk easier.

Share this post


Link to post
Share on other sites

I might be wrong but, in c++/opengl at least, you don't use the OnPaint message to draw something, you use your own rendering method.

I haven't done c#/xna in age tough, so i cannot be sure.

Share this post


Link to post
Share on other sites

You probably need to force a redraw whenever the controls are idle. A straightforward way shown here is using a Timer control, and using the Timer.Tick method to call Invalidate, telling the control to draw itself again. I've seen this used in the XNA Winforms sample.

 

Moving to XNA would be a good choice- it takes over the message loop in its looping functions.

Share this post


Link to post
Share on other sites

My problem ended up being trying to run my main game loop inside my constructor for the control, rather than after...  I could still transition to XNA, but does anyone know of any good, free libraries for XNA which give basic user-controls, like text boxes (input/output), drop down combo-boxes, etc?  If not, I may still wing it just for project velocity's sake :)

Share this post


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

  • Advertisement