Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Time/Clock  (Read 3639 times)

0 Members and 1 Guest are viewing this topic.

greenman76

  • Newbie
  • *
  • Posts: 2
    • View Profile
Time/Clock
« 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?

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Time/Clock
« Reply #1 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.

greenman76

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Time/Clock
« Reply #2 on: March 03, 2015, 07:23:16 pm »
Thanks, that fixed it.  8)

 

anything