Game Development Reference
The kjAjpanBn]ia event handler is responsible for using these variables to calculate velocity:
It might look a little convoluted, but what's happening is really very mundane:
1. The object's velocity is calculated by comparing its current position with the position that it
was at in the previous frame. kh`T and kh`U store the object's previous position. For example,
if the object was at position 100 in the previous frame and at 105 in the current frame, its
velocity would be 5.
2. You need to store the object's current position in the kh`T and kh`U variables so that you can
access these values in the next frame. The object's current position becomes its old position
when the frame advances:
With this system, you can capture an animated object's velocity and use it for any other calculations
or collision detection that your game might need to do.
Although this system for calculating velocity will hold you in good stead in a situation like this, you
might work on a game in which you need to calculate velocity and update the player's position at the
same time. In that case, you need to use additional variables that temporarily store the current t and
u values. This is necessary so that current x and y values aren't lost when the new velocity is added to
the object's position.