Created
July 22, 2013 10:24
-
-
Save posva/6052868 to your computer and use it in GitHub Desktop.
Simple FPS display for SFML2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <SFML/Graphics/Text.hpp> | |
#include <SFML/System/Clock.hpp> | |
#include <sstream> | |
class FPS : public sf::Text { | |
sf::Clock myClock; | |
unsigned int mySteps; | |
public: | |
FPS(const sf::Font& font) : sf::Text("0", font), mySteps(0) | |
{} | |
void step() | |
{ | |
++mySteps; | |
float time(myClock.getElapsedTime().asSeconds()); | |
if (time >= 1.f) | |
{ | |
std::ostringstream str; str.precision(4); | |
str<<mySteps/time; | |
setString(str.str()); | |
mySteps = 0; | |
myClock.restart(); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment