Game Loop Not Repainting

Started by
3 comments, last by jtd200 11 years, 2 months ago

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?

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.

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.

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.

New game in progress: Project SeedWorld

My development blog: Electronic Meteor

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 :)

This topic is closed to new replies.

Advertisement