Skip to main content
deleted 145 characters in body; edited title
Source Link
House
  • 73.5k
  • 17
  • 188
  • 276

{C++ SFML} Really simple cooldown helpcount down timer

To start, I have basically dyslexia but for Maths so I struggle at the pure basics of maths, which really sucks.

Anyway, onwards.

I'm making a little 2D tank game that fires bullets depending on where you click (This has been done and works a treat).

I'm currently working on a timer class with a simple function that displays a little countdown depending on the inputted time. (This will be used for bullet fire delays).

bool timer makeTimer(int waitTime)

This is the start of the timer, it is a simple boolean function which returns "true" when the timer has reached 0.

I can make it decrement down until it reaches 0 easily, but the part I'm having issues with is making it countdown based on an actual time event, so once per second. I've tried lots of different things but I just can't get this darn part to work.

The variables I have to work with are;

waitTime // inputted timeDelay
sf::Clock // To show the elapsed time per frame
sf::seconds(1) // Not too sure if I need this

So, to wrap up.

  • I'm trying to get it to countdown from the inputedinputted time once per second.

Thanks

{C++ SFML} Really simple cooldown help

To start, I have basically dyslexia but for Maths so I struggle at the pure basics of maths, which really sucks.

Anyway, onwards.

I'm making a little 2D tank game that fires bullets depending on where you click (This has been done and works a treat).

I'm currently working on a timer class with a simple function that displays a little countdown depending on the inputted time. (This will be used for bullet fire delays).

bool timer makeTimer(int waitTime)

This is the start of the timer, it is a simple boolean function which returns "true" when the timer has reached 0.

I can make it decrement down until it reaches 0 easily, but the part I'm having issues with is making it countdown based on an actual time event, so once per second. I've tried lots of different things but I just can't get this darn part to work.

The variables I have to work with are;

waitTime // inputted timeDelay
sf::Clock // To show the elapsed time per frame
sf::seconds(1) // Not too sure if I need this

So, to wrap up.

  • I'm trying to get it to countdown from the inputed time once per second.

Thanks

Really simple count down timer

I'm making a little 2D tank game that fires bullets depending on where you click (This has been done and works a treat).

I'm currently working on a timer class with a simple function that displays a little countdown depending on the inputted time. (This will be used for bullet fire delays).

bool timer makeTimer(int waitTime)

This is the start of the timer, it is a simple boolean function which returns "true" when the timer has reached 0.

I can make it decrement down until it reaches 0 easily, but the part I'm having issues with is making it countdown based on an actual time event, so once per second. I've tried lots of different things but I just can't get this darn part to work.

The variables I have to work with are;

waitTime // inputted timeDelay
sf::Clock // To show the elapsed time per frame
sf::seconds(1) // Not too sure if I need this

So, to wrap up.

  • I'm trying to get it to countdown from the inputted time once per second.
Rollback to Revision 1
Source Link
House
  • 73.5k
  • 17
  • 188
  • 276

To start, I have basically dyslexia but for Maths so I struggle at the pure basics of maths, which really sucks.

Anyway, onwards.

I'm making a little 2D tank game that fires bullets depending on where you click (This has been done and works a treat).

I'm currently working on a timer class with a simple function that displays a little countdown depending on the inputted time. (This will be used for bullet fire delays).

bool timer makeTimer(int waitTime)

This is the start of the timer, it is a simple boolean function which returns "true" when the timer has reached 0.

I can make it decrement down until it reaches 0 easily, but the part I'm having issues with is making it countdown based on an actual time event, so once per second. I've tried lots of different things but I just can't get this darn part to work.

The variables I have to work with are;

waitTime // inputted timeDelay
sf::Clock // To show the elapsed time per frame
sf::seconds(1) // Not too sure if I need this

So, to wrap up.

  • I'm trying to get it to countdown from the inputed time once per second.

Thanks

-- EDIT --

This is what I did to fix my issue;

bool hasFinished = false;

    sf::Clock clock;
    sf::Time elapsed = clock.restart();

    int timeStep = clock.getElapsedTime().asSeconds();
    int totalTime = waitTime;

    while(totalTime>=0)
    {
        totalTime = (waitTime) - clock.getElapsedTime().asSeconds();
        if(totalTime<=0)
        {
            hasFinished = true;
        }   
    }

    return hasFinished;

To start, I have basically dyslexia but for Maths so I struggle at the pure basics of maths, which really sucks.

Anyway, onwards.

I'm making a little 2D tank game that fires bullets depending on where you click (This has been done and works a treat).

I'm currently working on a timer class with a simple function that displays a little countdown depending on the inputted time. (This will be used for bullet fire delays).

bool timer makeTimer(int waitTime)

This is the start of the timer, it is a simple boolean function which returns "true" when the timer has reached 0.

I can make it decrement down until it reaches 0 easily, but the part I'm having issues with is making it countdown based on an actual time event, so once per second. I've tried lots of different things but I just can't get this darn part to work.

The variables I have to work with are;

waitTime // inputted timeDelay
sf::Clock // To show the elapsed time per frame
sf::seconds(1) // Not too sure if I need this

So, to wrap up.

  • I'm trying to get it to countdown from the inputed time once per second.

Thanks

-- EDIT --

This is what I did to fix my issue;

bool hasFinished = false;

    sf::Clock clock;
    sf::Time elapsed = clock.restart();

    int timeStep = clock.getElapsedTime().asSeconds();
    int totalTime = waitTime;

    while(totalTime>=0)
    {
        totalTime = (waitTime) - clock.getElapsedTime().asSeconds();
        if(totalTime<=0)
        {
            hasFinished = true;
        }   
    }

    return hasFinished;

To start, I have basically dyslexia but for Maths so I struggle at the pure basics of maths, which really sucks.

Anyway, onwards.

I'm making a little 2D tank game that fires bullets depending on where you click (This has been done and works a treat).

I'm currently working on a timer class with a simple function that displays a little countdown depending on the inputted time. (This will be used for bullet fire delays).

bool timer makeTimer(int waitTime)

This is the start of the timer, it is a simple boolean function which returns "true" when the timer has reached 0.

I can make it decrement down until it reaches 0 easily, but the part I'm having issues with is making it countdown based on an actual time event, so once per second. I've tried lots of different things but I just can't get this darn part to work.

The variables I have to work with are;

waitTime // inputted timeDelay
sf::Clock // To show the elapsed time per frame
sf::seconds(1) // Not too sure if I need this

So, to wrap up.

  • I'm trying to get it to countdown from the inputed time once per second.

Thanks

Tweeted twitter.com/#!/StackGameDev/status/490105659355308032
Modification
Source Link

To start, I have basically dyslexia but for Maths so I struggle at the pure basics of maths, which really sucks.

Anyway, onwards.

I'm making a little 2D tank game that fires bullets depending on where you click (This has been done and works a treat).

I'm currently working on a timer class with a simple function that displays a little countdown depending on the inputted time. (This will be used for bullet fire delays).

bool timer makeTimer(int waitTime)

This is the start of the timer, it is a simple boolean function which returns "true" when the timer has reached 0.

I can make it decrement down until it reaches 0 easily, but the part I'm having issues with is making it countdown based on an actual time event, so once per second. I've tried lots of different things but I just can't get this darn part to work.

The variables I have to work with are;

waitTime // inputted timeDelay
sf::Clock // To show the elapsed time per frame
sf::seconds(1) // Not too sure if I need this

So, to wrap up.

  • I'm trying to get it to countdown from the inputed time once per second.

Thanks

-- EDIT --

This is what I did to fix my issue;

bool hasFinished = false;

    sf::Clock clock;
    sf::Time elapsed = clock.restart();

    int timeStep = clock.getElapsedTime().asSeconds();
    int totalTime = waitTime;

    while(totalTime>=0)
    {
        totalTime = (waitTime) - clock.getElapsedTime().asSeconds();
        if(totalTime<=0)
        {
            hasFinished = true;
        }   
    }

    return hasFinished;

To start, I have basically dyslexia but for Maths so I struggle at the pure basics of maths, which really sucks.

Anyway, onwards.

I'm making a little 2D tank game that fires bullets depending on where you click (This has been done and works a treat).

I'm currently working on a timer class with a simple function that displays a little countdown depending on the inputted time. (This will be used for bullet fire delays).

bool timer makeTimer(int waitTime)

This is the start of the timer, it is a simple boolean function which returns "true" when the timer has reached 0.

I can make it decrement down until it reaches 0 easily, but the part I'm having issues with is making it countdown based on an actual time event, so once per second. I've tried lots of different things but I just can't get this darn part to work.

The variables I have to work with are;

waitTime // inputted timeDelay
sf::Clock // To show the elapsed time per frame
sf::seconds(1) // Not too sure if I need this

So, to wrap up.

  • I'm trying to get it to countdown from the inputed time once per second.

Thanks

To start, I have basically dyslexia but for Maths so I struggle at the pure basics of maths, which really sucks.

Anyway, onwards.

I'm making a little 2D tank game that fires bullets depending on where you click (This has been done and works a treat).

I'm currently working on a timer class with a simple function that displays a little countdown depending on the inputted time. (This will be used for bullet fire delays).

bool timer makeTimer(int waitTime)

This is the start of the timer, it is a simple boolean function which returns "true" when the timer has reached 0.

I can make it decrement down until it reaches 0 easily, but the part I'm having issues with is making it countdown based on an actual time event, so once per second. I've tried lots of different things but I just can't get this darn part to work.

The variables I have to work with are;

waitTime // inputted timeDelay
sf::Clock // To show the elapsed time per frame
sf::seconds(1) // Not too sure if I need this

So, to wrap up.

  • I'm trying to get it to countdown from the inputed time once per second.

Thanks

-- EDIT --

This is what I did to fix my issue;

bool hasFinished = false;

    sf::Clock clock;
    sf::Time elapsed = clock.restart();

    int timeStep = clock.getElapsedTime().asSeconds();
    int totalTime = waitTime;

    while(totalTime>=0)
    {
        totalTime = (waitTime) - clock.getElapsedTime().asSeconds();
        if(totalTime<=0)
        {
            hasFinished = true;
        }   
    }

    return hasFinished;
Source Link
Loading