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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - S0urce

Pages: [1]
1
System / Re: [Help] I don't understand sf::Time, sf::Clock
« on: November 28, 2019, 01:18:33 pm »
The 'yellow' loop is a way of processing fixed timesteps when frame times even though frame times are not actually this length of time.
For more information, this article could help. Be aware that how this works can be rather complicated or confusing at first.

For a more simple "blueprint" that is easier to understand, try:

// ...
sf::Clock clock
sf::Time frameTime{ sf::Time::Zero };

while (window.isOpen())
{
    // ...

    frameTime = clock.restart();

    window.clear();

    window.display();
}

// ...

You can see that there is only one line instead of that yellow loop and it basically stores how long it took since last time it was here (each time the clock is restarted, it returns how long it was running).

Then, you can simply multiply any motions or other values that change over time by that frame time - commonly by it in seconds:
position += velocity * frameTime.asSeconds();


Thanks for your reply. I'm getting better;

sf::Time timer = sf::Time::Zero;
timer += clock.getElapsedTime();   // This happen while bool gameOver is false.
text.setString("Time: " + std::to_string(this->timer.asSeconds())); // This is what I have in my update-loop.

But how do I cut decimals off timer? I would like to decide if 1s, or 1.5s, or 1.52s (you get the picture) should be presented instead of 1.52123124s

2
System / Re: [Help] I don't understand sf::Time, sf::Clock
« on: November 04, 2019, 12:25:45 pm »
Hi !

I tried, in different ways, but the code did not work.
I've read the material/tutorials and they are aweful.

3
System / [Help] I don't understand sf::Time, sf::Clock
« on: November 03, 2019, 08:47:23 pm »
Hello everyone !
 
I'm new on this community-platform and this is also my first post, so please be gentle.

I'm using a SFML blueprint for my project, but I don't understand everything in it. By that, I mean specifically sf::Clock and sf::Time. I have spent so much sf::time (haha, get it?) reading and trying to understand it, that I in the end gave up and came here for help.

This is the blueprint I'm talking about: read attachment.

Now, there're two while-loops in it. The red is just for keeping the window open/program running, but the yellow one has something to do with time. Mind explaining?

Also, I want to create a timer. That show the time in seconds and gets reset if time is X.

Pages: [1]