Jump to content
  • Advertisement
Sign in to follow this  
JDUK

Timing D'Draw frame rate,drawing etc.(C#)

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

My scrolling tile engine is really my 1st foray into DirectDraw and while im developing it all the draw functions are just sitting in an Override of OnPaint. But this is giving choppy performance and i want to put it in a timed loop so it only draws 30 times a second. Problem is i can find no definative way of doing this searching the internet i find a whole host of suggestion from threads to getTime to DXUtil.Timer and just as many replies saying "That way is over the top", "that way does not provide enough accuracy or the frequnecy is to low", etc, etc. Can any one just pin it down to one simple way that is perfectly adequate for an 8-Way scrolling platformer that will leave no noticable performance choppyness to the naked eye? Thanks

Share this post


Link to post
Share on other sites
Advertisement
No OnPaint(). Just render in a tight loop. Seriously.

				
using (Form form = new Form())
{
form.Show();
form.Activate();

while (form.Created)
{
form.Draw();
gameEngine.Render(); // All your DDraw stuff
Application.DoEvents();
}
}



Now, make all your *animations* time-based (usually considered the best practice). With a timer, you should be able to calculate or get the change in time since the last time animate was called. Use this change in time to determine how much to move or change something.

Share this post


Link to post
Share on other sites
Thanks guys this is how im doing the timing at the mo

[source lang ="c#"]
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
{
ip.ReadKeyboard(ref PosX, ref PosY);
te.TileUpdate(ref PosX,ref PosY);
elapsedtime = DXUtil.Timer(DirectXTimer.GetApplicationTime);
if((elapsedtime-lasttime) > 0.03f)
{
te.Draw();
lasttime= DXUtil.Timer(DirectXTimer.GetApplicationTime);
}
this.Invalidate();
}




this controls my frames persecond so its not cauing chopyness.
Now i have the problem of regulating the tile updating and input
should i just bung them inside the timer loop? or is there abeter way?

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!