Timing D'Draw frame rate,drawing etc.(C#)
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
No OnPaint(). Just render in a tight loop. Seriously.
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.
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.
Thanks guys this is how im doing the timing at the mo
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?
[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?
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement