Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

Game Loop Not Repainting

Started by jtd200 Mar 6, 2013 at 6:51 PM 3 replies 1.5k views
Original Post
jtd200
jtd200

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?

jtd200
jtd200

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.

Vortez
Vortez

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.

CC Ricers
CC Ricers

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.

jtd200
jtd200

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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.