time-based: migrada escena Intro (dual-API a MovingSprite/SmartSprite/Writer, constants a 60Hz)
This commit is contained in:
@@ -35,6 +35,31 @@ void Writer::update() {
|
||||
}
|
||||
}
|
||||
|
||||
// Time-based: avanca un caracter cada `seconds_per_char_` i un cop completat
|
||||
// es queda visible `remaining_time_s_` segons abans de finalitzar.
|
||||
void Writer::update(float dt_s) {
|
||||
if (!enabled_) { return; }
|
||||
|
||||
if (!completed_) {
|
||||
char_timer_s_ += dt_s;
|
||||
while (char_timer_s_ >= seconds_per_char_ && index_ < length_) {
|
||||
char_timer_s_ -= seconds_per_char_;
|
||||
++index_;
|
||||
}
|
||||
if (index_ >= length_) {
|
||||
completed_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (completed_) {
|
||||
if (remaining_time_s_ <= 0.0F) {
|
||||
finished_ = true;
|
||||
} else {
|
||||
remaining_time_s_ -= dt_s;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja el objeto en pantalla
|
||||
void Writer::render() {
|
||||
if (enabled_) {
|
||||
@@ -69,6 +94,12 @@ void Writer::setSpeed(int value) {
|
||||
writing_counter_ = value;
|
||||
}
|
||||
|
||||
// Time-based: segons per caracter. Quan s'usa, l'update(dt) avança index.
|
||||
void Writer::setSecondsPerChar(float seconds) {
|
||||
seconds_per_char_ = seconds;
|
||||
char_timer_s_ = 0.0F;
|
||||
}
|
||||
|
||||
// Establece el valor de la variable
|
||||
void Writer::setEnabled(bool value) {
|
||||
enabled_ = value;
|
||||
@@ -89,6 +120,15 @@ auto Writer::getEnabledCounter() const -> int {
|
||||
return enabled_counter_;
|
||||
}
|
||||
|
||||
// Time-based: temps que es mante visible despres de completar el text.
|
||||
void Writer::setRemainingTime(float seconds) {
|
||||
remaining_time_s_ = seconds;
|
||||
}
|
||||
|
||||
auto Writer::getRemainingTime() const -> float {
|
||||
return remaining_time_s_;
|
||||
}
|
||||
|
||||
// Centra la cadena de texto a un punto X
|
||||
void Writer::center(int x) {
|
||||
setPosX(x - (text_->lenght(caption_, kerning_) / 2));
|
||||
|
||||
Reference in New Issue
Block a user