From 6e56a6fd7970944b0b44d33ef872e51b40c0016e Mon Sep 17 00:00:00 2001 From: Sergio Valor Date: Tue, 30 Sep 2025 13:47:48 +0200 Subject: [PATCH] =?UTF-8?q?moving=5Fsprite.cpp:=20afegits=20nous=20metodes?= =?UTF-8?q?=20per=20controlar=20la=20rotaci=C3=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/moving_sprite.cpp | 13 +++++++++++++ source/moving_sprite.h | 2 ++ 2 files changed, 15 insertions(+) diff --git a/source/moving_sprite.cpp b/source/moving_sprite.cpp index 49d4c8c..73f1c0f 100644 --- a/source/moving_sprite.cpp +++ b/source/moving_sprite.cpp @@ -90,6 +90,19 @@ void MovingSprite::setRotate(bool enable) { rotate_.enabled = enable; } +// Habilita la rotación y establece el centro en el centro del sprite +void MovingSprite::startRotate() { + rotate_.enabled = true; + rotate_.center.x = pos_.w / 2.0F; + rotate_.center.y = pos_.h / 2.0F; +} + +// Detiene la rotación y resetea el ángulo a cero +void MovingSprite::stopRotate() { + rotate_.enabled = false; + rotate_.angle = 0.0; +} + // Establece la posición y_ el tamaño del objeto void MovingSprite::setPos(SDL_FRect rect) { x_ = rect.x; diff --git a/source/moving_sprite.h b/source/moving_sprite.h index 5b7a9d3..9f7496f 100644 --- a/source/moving_sprite.h +++ b/source/moving_sprite.h @@ -46,6 +46,8 @@ class MovingSprite : public Sprite { void setAngle(double value) { rotate_.angle = value; } // Establece el ángulo void setRotatingCenter(SDL_FPoint point) { rotate_.center = point; } // Establece el centro de rotación void setRotate(bool enable); // Activa o desactiva el efecto de rotación + void startRotate(); // Habilita la rotación con centro automático + void stopRotate(); // Detiene la rotación y resetea ángulo void setRotateAmount(double value) { rotate_.amount = value; } // Establece la cantidad de rotación void switchRotate() { rotate_.amount *= -1; } // Cambia el sentido de la rotación void setFlip(SDL_FlipMode flip) { flip_ = flip; } // Establece el flip