We're going to employ delta time to make our cycle move at a constant speed instead of a speed based on frame rate. Once we have that done, we'll learn how to use delta time to protect against hiccups in the game—moments when the time between frames is abnormally large, and could cause the action to skip forward.
We need to make two changes to use delta time for our cycle's movement. This first is to add this line at the beginning of our
cycleMove
method:dt = globalClock.getDt()
This will create a temporary variable and fill it with the delta time from
globalClock
in one go. The delta time we get will be in full seconds, so if we want our cycle to move at 10 units per second, we need to change our call tosetY
incycleMove
to the following:self.cycle1.setY(self.cycle1, 10 * dt) def cycleMove(self, task): dt = globalClock.getDt() self.cycle1.setY(self.cycle1, 10 * dt) return task.cont
Save the file as
chp03_06.py
and run it.If our frame...