diff --git a/resources/config/ui.json b/resources/config/ui.json index 678e35e..644f035 100644 --- a/resources/config/ui.json +++ b/resources/config/ui.json @@ -163,7 +163,19 @@ "hover": "resources/shoot_hover.png", "pressed": "resources/shoot_pressed.png" } - } + }, + { + "type": "TextView", + "name": "velocityText", + "x": 10, + "y": 10, + "width": 200, + "height": 40, + "text": "Velocity: 0", + "fontSize": 24, + "color": [1.0, 1.0, 1.0, 1.0], + "centered": false + } ] } } \ No newline at end of file diff --git a/src/Game.cpp b/src/Game.cpp index 6ba12ce..b364b59 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -1216,8 +1216,13 @@ namespace ZL } // update velocity text - std::string velocityStr = "Velocity: " + std::to_string(static_cast(Environment::shipState.velocity)); - uiManager.setText("velocityText", velocityStr); + if (shipAlive && !gameOver) { + auto velocityTv = uiManager.findTextView("velocityText"); + if (velocityTv) { + std::string velocityStr = "Velocity: " + std::to_string(static_cast(Environment::shipState.velocity)); + uiManager.setText("velocityText", velocityStr); + } + } uiManager.update(static_cast(delta)); lastTickCount = newTickCount; diff --git a/src/UiManager.cpp b/src/UiManager.cpp index 9cf0d94..86a4fb5 100644 --- a/src/UiManager.cpp +++ b/src/UiManager.cpp @@ -903,7 +903,6 @@ namespace ZL { bool UiManager::setText(const std::string& name, const std::string& newText) { auto tv = findTextView(name); if (!tv) { - std::cerr << "TextView not found: " << name << std::endl; return false; } tv->text = newText;