migració a delta time

This commit is contained in:
2025-09-16 10:48:22 +02:00
parent 6c702e7e23
commit 7579594c22
8 changed files with 189 additions and 91 deletions

View File

@@ -3,15 +3,14 @@
#include "text.h" // Para Text
// Actualiza el objeto
void Writer::update() {
void Writer::update(float delta_time) {
if (enabled_) {
if (!completed_) {
// No completado
if (writing_counter_ > 0) {
writing_counter_--;
} else {
writing_timer_ += delta_time;
if (writing_timer_ >= speed_ms_) {
index_++;
writing_counter_ = speed_;
writing_timer_ = 0.0f;
}
if (index_ == length_) {
@@ -19,10 +18,8 @@ void Writer::update() {
}
} else {
// Completado
finished_ = enabled_counter_ <= 0;
if (!finished_) {
enabled_counter_--;
}
enabled_timer_ += delta_time;
finished_ = enabled_timer_ >= enabled_timer_target_;
}
}
}
@@ -57,8 +54,10 @@ void Writer::setCaption(const std::string &text) {
// Establece el valor de la variable
void Writer::setSpeed(int value) {
speed_ = value;
writing_counter_ = value;
// Convierte frames a milisegundos (frames * 16.67ms)
constexpr float FRAME_TIME_MS = 1000.0f / 60.0f;
speed_ms_ = static_cast<float>(value) * FRAME_TIME_MS;
writing_timer_ = 0.0f;
}
// Establece el valor de la variable
@@ -73,7 +72,10 @@ auto Writer::isEnabled() const -> bool {
// Establece el valor de la variable
void Writer::setFinishedCounter(int time) {
enabled_counter_ = time;
// Convierte frames a milisegundos (frames * 16.67ms)
constexpr float FRAME_TIME_MS = 1000.0f / 60.0f;
enabled_timer_target_ = static_cast<float>(time) * FRAME_TIME_MS;
enabled_timer_ = 0.0f;
}
// Centra la cadena de texto a un punto X