Jump to content


Photo

Delta Timing Drawing


  • Please log in to reply
1 reply to this topic

#1 gmx0

gmx0

    The Messenger

  • GMC Member
  • 1182 posts
  • Version:GM6

Posted 03 January 2012 - 01:03 AM

On working with my RTS Ground Zero CLASH, every time I did something that lagged the CPU, the FPS dropped significantly ("Well, duh," you say). The mouse would start to be moving erratically.

This is simple to fix, really. And it will make your games a lot faster, especially if you have to draw a lot of objects on-screen.
This tutorial assumes you have a persistent, global control object. If not, make one now. Make sure to put it in the first room of the game. It usually is tasked with all the global variables and what not, but we are also going to use it for drawing.
In the Create or Game Start Event:
set_automatic_draw(false);
//this makes it so that the game will not draw anything AT ALL, unless you tell it to
ct=current_time;
//cgrrent_time is in milliseconds. That is all you need to know

In the Step, Begin Step, AND End Step Event:
//34 milliseconds is 1/30 of a second rounded up. You can use 67(1/15) and 133(10/75) and so on.
if current_time>=ct+34
screen_redraw();
//executes the Draw Event
ct=current_time;
//resets current_time to now


The catch to this is that the FPS variable will not give you the correct value.
So how does thing actually makes the game smoother and faster?
The screen is only drawn when 1/30 of a second actually passes, and it does not fully depend on the processor power. So if your CPU is in a heavy calculation, it will not freeze, but draw something still.
The limitations of this approach is often because the Begin Step and Step Events. If you have any sprite-changing or image-manipulating on those two events, it may get buggy but it really depends on your coding architecture.

Happy Delta Timing Drawing!

Edited by gmx0, 03 January 2012 - 01:59 AM.

  • 0

#2 ean

ean

    GMC Member

  • New Member
  • 190 posts
  • Version:GM8

Posted 03 January 2012 - 01:14 AM

Just to let you know, don't perform any game critical code in the Draw Event if you use this.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users