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

Author Topic: SFML game development book stopping a clock in another state  (Read 3663 times)

0 Members and 1 Guest are viewing this topic.

devilswin

  • Newbie
  • *
  • Posts: 38
    • View Profile
    • Email
So I am using the majority of the book's systems for my version of pong. However for my version of pong, I want to have a level system that has a countdown timer, and when the timer hits zero, a state is pushed that has a timer that says new level. Then in the gamestate, a class that has the attributes of the level increased.  I tried doing this, but the issue us that even though the pause state  or the new level state was pushed to the top, the sf:clock is still running, thus making this new state useless, as the level can end if the player sits in the pause screen for a given amount of time. I am on my phone posting this so I do apologize
« Last Edit: July 15, 2015, 05:41:26 pm by devilswin »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: SFML game development book stopping a clock in another state
« Reply #1 on: July 15, 2015, 07:25:25 pm »
You could just restart the clock and time the next state from the beginning. If you need a overall time, you could add the time to a separate, accumulated time just before restarting (or during since restart also returns the elapsed time).

I believe that Thor has a callback timer, which may be of some interest to you, especially if you're already using Thor.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: SFML game development book stopping a clock in another state
« Reply #2 on: July 15, 2015, 09:26:55 pm »
You're measuring game time, not real time, so sf::Clock is the wrong tool.

A simple sf::Time variable which accumulates the frame time is a good choice. This automatically works when you pause the game, suspend a state, etc.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

devilswin

  • Newbie
  • *
  • Posts: 38
    • View Profile
    • Email
Re: SFML game development book stopping a clock in another state
« Reply #3 on: July 16, 2015, 06:26:36 pm »
Hmm, I will have enough to look into a way of doing that with the frame time, but it is stoppage? So that I could have a true pause. Now that I FINALLY got Thor working I could try the time classes in it.

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: SFML game development book stopping a clock in another state
« Reply #4 on: July 16, 2015, 09:57:43 pm »
You didn't understand what I meant. You don't need any clocks, you need time values (sf::Time) which you accumulate.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

devilswin

  • Newbie
  • *
  • Posts: 38
    • View Profile
    • Email
Re: SFML game development book stopping a clock in another state
« Reply #5 on: July 17, 2015, 07:00:54 pm »
Ohhhhhh I see now, makes much more sense