Created
October 30, 2013 14:52
-
-
Save kenpower/7233967 to your computer and use it in GitHub Desktop.
FPS counter for SFML
This file contains hidden or 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
class FPS | |
{ | |
public: | |
/// @brief Constructor with initialization. | |
/// | |
FPS() : mFrame(0), mFps(0) {} | |
/// @brief Update the frame count. | |
/// | |
/// @brief Get the current FPS count. | |
/// @return FPS count. | |
const unsigned int getFPS() const { return mFps; } | |
private: | |
unsigned int mFrame; | |
unsigned int mFps; | |
sf::Clock mClock; | |
public: | |
void update() | |
{ | |
if(mClock.getElapsedTime().asSeconds() >= 1.f) | |
{ | |
mFps = mFrame; | |
mFrame = 0; | |
mClock.restart(); | |
} | |
++mFrame; | |
} | |
}; |
This file contains hidden or 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
FPS fps; | |
while (window.isOpen()) | |
{ | |
// game loop stuff; | |
fps.update(); | |
std::ostringstream ss; | |
ss << fps.getFPS(); | |
window.setTitle(ss.str()); | |
} |
Thanks! This helped my project!
thx random people on the internet
Hippity hoppity your code is now my property
It would be nice if there were a built in FPS count widget (like in RayLib).
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks!