Hi guys, a few days before i started programming in SFML and i'm stucked in one moment, exactly in making cooldowns. I wanted to make a basic attack depending on attackspeedplayer variable, but the program clock doesn't want to update more often than 1 sec, so when i run this program i'll get something like this:
0,66666667
-0,3333333
-1,3333333
but the if will be skipped.
Is there any other way to make it properly?
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <iostream>
using namespace std;
int main()
{
float attackspeedplayer = 1.5;
float attackspeedtotal = 1 / attackspeedplayer;
sf::RenderWindow window( sf::VideoMode( 200, 200 ), "SFML works!" );
sf::CircleShape shape( 100.f );
shape.setFillColor( sf::Color::Green );
sf::Clock clock;
sf::Time elapsed;
while( window.isOpen() )
{
elapsed = clock.getElapsedTime();
cout << attackspeedtotal - elapsed.asMilliseconds() / 1000 << endl;
if( attackspeedtotal - elapsed.asMilliseconds() / 1000 == 0 )
{
cout << "CD minal!";
}
sf::Event event;
while( window.pollEvent( event ) )
{
if( event.type == sf::Event::Closed )
window.close();
}
window.clear();
window.display();
}
return 0;
}