The leapfrog method works by using a variable at a non-integer time step to determine the new value of a different variable.
Image demonstrating the leapfrog method http://einstein.drexel.edu/courses/Comp_Phys/Integrators/leapfrog/leapfrog.gif
So the new position values are calculated using the velocity half a time step ahead of the position. This is done for the same reason that a similar method is used in the mid-point method (however the leapfrog method has some advantages i.e. it is reversible and hence useful for oscillating systems).
If you want to run the leapfrog method one possible way is using,
dt = time since last frame
for every object:
// If first time object is moved determine velocity at midpoint
object.velocity += acceleration * dt / 2
object.position += object.velocity * dt
for every object:
acceleration = object.calculate_acceleration()
object.velocity += acceleration * dt
So the objects store the velocity not at the given time step but at time step + 1/2.
Since you are not storing the velocity at a particular time step but instead at time step + 1/2 any processes which use this velocity for calculations may not be correct.
This is also true for the acceleration, the leapfrog method assumes that the acceleration does not depend on the velocity. So the acceleration only depends on the position, hence the velocity 'leaps' over the position.
However, if your
object.calculate_acceleration() function uses the velocity then it will not be a true leapfrog method as the velocity will be leaping over itself and you will be using information both from the current time step and the time step + 1/2.
Example; friction in the form of drag is often dependent on
velocity^2 (as one would expect the faster the object the larger the drag).
The added line in my code snippet is simply changing the initial velocity to the new time step. If this is not important then you simply return to the normal Euler integration
On the order of the method
According to wikipedia the leapfrog method can also be written as,
which is a second order method. These equations can also be used to perform your integration and may be easier to understand. Again note that here the acceleration cannot depend on the velocity otherwise the second equation becomes much more complicated.