Expanding a little on what I think you're doing based on the outline of your code, your onDrawFrame()
method in pseudo code looks like this:
deltaTime = SystemClock.elapsedRealtime() - lastFrameTrime
// point 1, see text below
update animation based on deltaTime
draw frame
// point 2, see text below
lastFrameTime = SystemClock.elapsedRealtime()
The problem with this sequence is that you lose the time between point 1 and point 2 from your total animation time. You need to make sure that the total sum of all your deltaTime
values, which are the times applied to your animation, covers the entire wall clock time of the amimation. With the logic you use, this is not the case. You only add up the times between the end of one call to the start of the next call. You do not account for the time needed to execute the method, which can be significant.
This can be fixed with a slight change in the sequence:
currentTime = SystemClock.elapsedRealtime()
deltaTime = currentTime - lastFrameTime
lastFrameTime = currentTime
update animation based on deltaTime
draw frame
The key point is that you only call elapsedRealtime()
once per frame.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…