aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJAROWMR <jarorutjes07@gmail.com>2025-01-06 13:43:28 +0100
committerJAROWMR <jarorutjes07@gmail.com>2025-01-06 13:43:28 +0100
commitce655acf72c5d5be62497dbaac41af7ef49be411 (patch)
treebbcd5ba7a6e4fd3c659cfb422da3783d77288408
parenta216cfc457cdde754c5673e9423d00147a2f1574 (diff)
added fps counter
-rw-r--r--game/hud/HudScript.cpp14
-rw-r--r--game/hud/HudScript.h1
-rw-r--r--game/hud/HudSubScene.cpp2
3 files changed, 16 insertions, 1 deletions
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<KeyPressEvent>([this](const KeyPressEvent & ev) -> bool {
+ if(ev.key != Keycode::END) return false;
+ Text & txt_fps = this->get_components_by_name<Text>(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<Text>(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;
}