From ce655acf72c5d5be62497dbaac41af7ef49be411 Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Mon, 6 Jan 2025 13:43:28 +0100 Subject: added fps counter --- game/hud/HudScript.cpp | 14 ++++++++++++++ game/hud/HudScript.h | 1 + game/hud/HudSubScene.cpp | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/game/hud/HudScript.cpp b/game/hud/HudScript.cpp index 71c84a1..496a03d 100644 --- a/game/hud/HudScript.cpp +++ b/game/hud/HudScript.cpp @@ -17,6 +17,20 @@ void HudScript::init() { txt.text = record; txt.dimensions = {BEST_CHAR_WIDTH*record.size(),(BEST_CHAR_WIDTH)*2}; txt.offset = TOP_LEFT+FONTOFFSET+BEST_OFFSET + vec2{record.size() * BEST_CHAR_WIDTH/2,0}; + + this->subscribe([this](const KeyPressEvent & ev) -> bool { + if(ev.key != Keycode::END) return false; + Text & txt_fps = this->get_components_by_name(HUD_FPS).front(); + this->show_fps = !this->show_fps; + if(this->show_fps) + { + txt_fps.active = true; + } + else { + txt_fps.active = false; + } + return true; + }); } void HudScript::frame_update(crepe::duration_t dt) { diff --git a/game/hud/HudScript.h b/game/hud/HudScript.h index aa92582..8e7e8fc 100644 --- a/game/hud/HudScript.h +++ b/game/hud/HudScript.h @@ -9,4 +9,5 @@ public: void frame_update(crepe::duration_t dt) override; private: crepe::SaveManager* savemgr; + bool show_fps = false; }; diff --git a/game/hud/HudSubScene.cpp b/game/hud/HudSubScene.cpp index dd36d1c..4995624 100644 --- a/game/hud/HudSubScene.cpp +++ b/game/hud/HudSubScene.cpp @@ -40,5 +40,5 @@ void HudSubScene::create(Scene & scn){ hud_fps.add_component(size_fps, FONT,Text::Data{ .world_space = false, .text_color = Color::GREEN, - }, TOP_LEFT+FONTOFFSET+FPS_OFFSET + vec2{FPS_LENGTH * FPS_CHAR_WIDTH/2,0}, FPS); + }, TOP_LEFT+FONTOFFSET+FPS_OFFSET + vec2{FPS_LENGTH * FPS_CHAR_WIDTH/2,0}, FPS).active = false; } -- cgit v1.2.3