Sign in to follow this  

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

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

This topic is 4745 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this