Every scheduled function takes a dt parameter, giving the actual "wall clock" time that passed since the previous invocation (or the time the function was scheduled, if it's the first period). This parameter can be used for numerical integration.
For example, a non-accelerating particle with velocity v will travel some distance over a change in time dt. This distance is calculated as v * dt. Similarly, a particle under constant acceleration a will have a change in velocity of a * dt.
The following example demonstrates a simple way to move a sprite across the screen at exactly 10 pixels per second:
sprite = pyglet.sprite.Sprite(image) sprite.dx = 10.0 def update(dt): sprite.x += sprite.dx * dt pyglet.clock.schedule_interval(update, 1/60.0) # update at 60Hz
This is a robust technique for simple animation, as the velocity will remain constant regardless of the speed or load of the computer.
Some examples of other common animation variables are given in the table below.
Animation parameter Distance Velocity Rotation Degrees Degrees per second Position Pixels Pixels per second Keyframes Frame number Frames per second