Moving with time instead of cpu bound movement.

Hi,

I’m wondering how do you use time when you want to move for example a tetris one place down?
I currently use this:

        for(int i=0;i<MOVE_DELAY;i++) {
        piece.move(piece.down);
}

I’ve seen on this site
this game loop

    float t = 0.0f;

    float currentTime = time();

    while (!quit)
    {
         float newTime = time();
         float dt = newTime - currentTime;
         currentTime = newTime;

         integrate(state, t, dt);
         t += dt;

         render(state);
    }

from http://www.gaffer.org/game-physics/fix-your-timestep/
and I don’t understand this line: render(state);
how would you use that state?

If you are new to animation and you want to develop a good main game loop, I highly recommend reading (online) chapter 2 of:
http://fivedots.coe.psu.ac.th/~ad/jg/

Or just buy the book, as I did. At the end of the chapter you will have a clear idea of how a good ani loop should work. Then it should also be much easier to understand the code you copied from gaffer.com. :smiley:

Key to your Tetris animation will be to choose a fixed timeslot and do an update() once each timeslot, and then render. If rendering falls behind, you compensate by doing more update(), until the updates are in synch with the time.

For frame timing management there are a few approaches. You could look at a short tutorial on the javag.org site. http://javag.org/?q=node/1

Travis

hi! I’ve been working with Timing Frameworking for past 2 years now and here’s one of the conferences I watched for a while. It’s french spoken but an english powerpoint presentation. You can find more at swinglabs.org. Thanks to Romain Guy who also helped me a lot !
http://java.developpez.tv/javadesktop-dec2005/#Part20
I’ve really enjoyed this conference, though I’ve been participating through the web only. What an amazing guy !
:smiley: