Quantcast
Channel: Question and Answer » game-loop
Viewing all articles
Browse latest Browse all 30

Smooth animation using delta times – big delays ocurring …

$
0
0

I’m writing a game on Android using OpenGL ES 2.0 for fun. I’m developing on Samsung Galaxy Note 3. I want to try to master smooth animation, i.e. correct frame transition and movement. I am focusing on frame transition first.

My onDrawFrame() code is:

@Override
public void onDrawFrame(GL10 glUnused)
{       
    time_x0 = System.currentTimeMillis();

    updateGame();   // this accesses the static variable time_delta
    drawGame();

    time_x1 = System.currentTimeMillis();
    time_delta = time_x1 - time_x0;
}

My updateGame() code looks like this:

    frame_time_counter += MyMainClass.time_delta;

    if(frame_time_counter >= active_anim.frame_time_change)
    {
        frame_time_counter %= active_anim.frame_time_change;
        frame_counter++;

        if(frame_counter == active_anim.frames.size())
            frame_counter = 0;

        // change the texture
        mTexture = active_anim.frames.get(frame_counter);
    }

The active_anim.frame_time_change is pre-calculated using:

    frame_time_change = 1000 / fps;

Now, the code animates, but not as expected. For example if I set fps=1 so that the animation should change frame every 1 second, in fact it takes much much longer to chaage frame, e.g. every 10 second or more…

I can’t figure out what I’m doing wrong. Any constructive comments/help appreciated.


Viewing all articles
Browse latest Browse all 30

Trending Articles