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

@@ -207,24 +207,21 @@ void Intro::switchText(int from_index, int to_index) {
}
// Actualiza las variables del objeto
void Intro::update() {
if (SDL_GetTicks() - ticks_ > param.game.speed) {
ticks_ = SDL_GetTicks(); // Actualiza el contador de ticks
Screen::get()->update(); // Actualiza el objeto screen
void Intro::update(float delta_time) {
Screen::get()->update(); // Actualiza el objeto screen
tiled_bg_->update(); // Actualiza el fondo
tiled_bg_->update(delta_time); // Actualiza el fondo
switch (state_) {
case State::SCENES:
updateSprites();
updateTexts();
updateScenes();
break;
switch (state_) {
case State::SCENES:
updateSprites(delta_time);
updateTexts(delta_time);
updateScenes();
break;
case State::POST:
updatePostState();
break;
}
case State::POST:
updatePostState();
break;
}
Audio::update();
@@ -253,12 +250,24 @@ void Intro::render() {
SCREEN->render(); // Vuelca el contenido del renderizador en pantalla
}
// Calcula el tiempo transcurrido desde el último frame
float Intro::calculateDeltaTime() {
const Uint64 current_time = SDL_GetTicks();
const float delta_time = static_cast<float>(current_time - last_time_);
last_time_ = current_time;
return delta_time;
}
// Bucle principal
void Intro::run() {
last_time_ = SDL_GetTicks();
Audio::get()->playMusic("intro.ogg", 0);
while (Section::name == Section::Name::INTRO) {
const float delta_time = calculateDeltaTime();
checkInput();
update();
update(delta_time);
checkEvents(); // Tiene que ir antes del render
render();
}
@@ -444,20 +453,20 @@ void Intro::initTexts() {
}
// Actualiza los sprites
void Intro::updateSprites() {
void Intro::updateSprites(float delta_time) {
for (auto &sprite : card_sprites_) {
sprite->update();
sprite->update(delta_time);
}
for (auto &sprite : shadow_sprites_) {
sprite->update();
sprite->update(delta_time);
}
}
// Actualiza los textos
void Intro::updateTexts() {
void Intro::updateTexts(float delta_time) {
for (auto &text : texts_) {
text->update();
text->update(delta_time);
}
}