Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Game Loop Not Repainting


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 jtd200   Members   -  Reputation: 105

Like
0Likes
Like

Posted 06 March 2013 - 12:51 PM

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?

 

 



Sponsor:

#2 jtd200   Members   -  Reputation: 105

Like
0Likes
Like

Posted 06 March 2013 - 01:35 PM

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.



#3 Vortez   Crossbones+   -  Reputation: 2704

Like
0Likes
Like

Posted 06 March 2013 - 01:52 PM

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.



#4 CC Ricers   Members   -  Reputation: 727

Like
1Likes
Like

Posted 06 March 2013 - 03:06 PM

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.


My development blog: Electronic Meteor

#5 jtd200   Members   -  Reputation: 105

Like
0Likes
Like

Posted 08 March 2013 - 05:36 PM

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






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS