SFML community forums

Help => System => Topic started by: greenman76 on March 03, 2015, 12:17:25 pm

Title: Time/Clock
Post by: greenman76 on March 03, 2015, 12:17:25 pm
I'm writing a Tetris game for class and I'm having a problem with getting the block to move down in incremented time. I've tried quite a few ways and searched all over but have not found a way that works for me.  Here is what I currently have. Hopefully someone can point out an obvious mistake.

while (window.isOpen() && lost == false)
   {
      
      //clear the window, draw the blocks, then display the window.
      window.clear();
   

      drawWell(*gameWell, LAYOUT_BOARD_TOP, LAYOUT_BOARD_LEFT, BLOCK_SIZE_PIXELS);
      drawTetrimino(tetriminoInPlay, LAYOUT_BOARD_TOP, LAYOUT_BOARD_LEFT, BLOCK_SIZE_PIXELS);
      window.display();
      


      sf::Clock clock;
      sf::Time dropTime = sf::milliseconds(100);
      sf::Time gameTime = clock.getElapsedTime();
      if (gameTime.asMilliseconds() > dropTime.asMilliseconds())
      { 
                        do stuff that needs doing
                 }

For some reason the stuff never gets done. What am I doing wrong?
Title: Re: Time/Clock
Post by: Jesper Juhl on March 03, 2015, 12:24:13 pm
You are continuously creating and destroying the "clock" object on the stack within the while() loop, so the elapsed time never gets a chance to accumulate.
Title: Re: Time/Clock
Post by: greenman76 on March 03, 2015, 07:23:16 pm
Thanks, that fixed it.  8)