delta-time: title.cpp

This commit is contained in:
2025-09-16 20:23:10 +02:00
parent 470a07d28c
commit 49e30f947a
9 changed files with 114 additions and 46 deletions

View File

@@ -67,11 +67,14 @@ void MovingSprite::move() {
// Mueve el sprite (time-based)
void MovingSprite::move(float deltaTime) {
x_ += vx_ * deltaTime;
y_ += vy_ * deltaTime;
// Convertir deltaTime (milisegundos) a factor de frame (asumiendo 60fps)
float frameFactor = deltaTime / (1000.0f / 60.0f);
x_ += vx_ * frameFactor;
y_ += vy_ * frameFactor;
vx_ += ax_ * deltaTime;
vy_ += ay_ * deltaTime;
vx_ += ax_ * frameFactor;
vy_ += ay_ * frameFactor;
pos_.x = static_cast<int>(x_);
pos_.y = static_cast<int>(y_);
@@ -106,9 +109,9 @@ void MovingSprite::rotate() {
// Establece la rotacion (time-based)
void MovingSprite::rotate(float deltaTime) {
if (rotate_.enabled) {
// Convertir speed (frames) a tiempo: speed frames = speed/60 segundos a 60fps
float rotationSpeed = static_cast<float>(rotate_.speed) / 60.0f;
rotate_.angle += rotate_.amount * (deltaTime / rotationSpeed);
// Convertir speed (frames) a tiempo: speed frames = speed * (1000ms/60fps) milisegundos
float rotationFrameTime = static_cast<float>(rotate_.speed) * (1000.0f / 60.0f);
rotate_.angle += rotate_.amount * (deltaTime / rotationFrameTime);
}
}