Showing FPS on title bar (GameEngine)

This commit is contained in:
John McCardle 2023-08-27 19:58:15 -04:00
parent ac0ec4bb71
commit ba97aebf3e
2 changed files with 6 additions and 1 deletions

View File

@ -11,7 +11,8 @@ GameEngine::GameEngine()
{ {
Resources::font.loadFromFile("./assets/JetbrainsMono.ttf"); Resources::font.loadFromFile("./assets/JetbrainsMono.ttf");
Resources::game = this; Resources::game = this;
window.create(sf::VideoMode(1024, 768), "McRogueFace - r/RoguelikeDev Tutorial Run"); window_title = "McRogueFace - r/RoguelikeDev Tutorial Run";
window.create(sf::VideoMode(1024, 768), window_title);
visible = window.getDefaultView(); visible = window.getDefaultView();
window.setFramerateLimit(30); window.setFramerateLimit(30);
scene = "uitest"; scene = "uitest";
@ -44,6 +45,7 @@ sf::RenderWindow & GameEngine::getWindow() { return window; }
void GameEngine::run() void GameEngine::run()
{ {
float fps = 0.0;
clock.restart(); clock.restart();
while (running) while (running)
{ {
@ -55,6 +57,8 @@ void GameEngine::run()
currentScene()->sRender(); currentScene()->sRender();
currentFrame++; currentFrame++;
frameTime = clock.restart().asSeconds(); frameTime = clock.restart().asSeconds();
fps = 1 / frameTime;
window.setTitle(window_title + " " + std::to_string(fps) + " FPS");
} }
} }

View File

@ -19,6 +19,7 @@ class GameEngine
sf::View visible; sf::View visible;
sf::Clock clock; sf::Clock clock;
float frameTime; float frameTime;
std::string window_title;
public: public:
GameEngine(); GameEngine();