migrat a SDL3
This commit is contained in:
+21
-26
@@ -3,72 +3,67 @@
|
||||
// Constructor
|
||||
Sprite::Sprite(Texture *texture)
|
||||
{
|
||||
this->texture = texture;
|
||||
pos = {0, 0, 0, 0};
|
||||
clip = {0, 0, 0, 0};
|
||||
frame = 0;
|
||||
numFrames = NUM_FRAMES;
|
||||
animationSpeed = 20;
|
||||
animationCounter = 0;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Sprite::~Sprite()
|
||||
{
|
||||
texture_ = texture;
|
||||
pos_ = {0, 0, 0, 0};
|
||||
clip_ = {0, 0, 0, 0};
|
||||
frame_ = 0;
|
||||
num_frames_ = NUM_FRAMES;
|
||||
animation_speed_ = 20;
|
||||
animation_counter_ = 0;
|
||||
}
|
||||
|
||||
// Establece la posición del sprite
|
||||
void Sprite::setPos(SDL_Point pos)
|
||||
{
|
||||
this->pos.x = pos.x;
|
||||
this->pos.y = pos.y;
|
||||
pos_.x = pos.x;
|
||||
pos_.y = pos.y;
|
||||
}
|
||||
|
||||
// Pinta el sprite
|
||||
void Sprite::render()
|
||||
{
|
||||
texture->render(&clip, &pos);
|
||||
texture_->render(&clip_, &pos_);
|
||||
}
|
||||
|
||||
// Actualiza la lógica de la clase
|
||||
void Sprite::update()
|
||||
{
|
||||
animationCounter++;
|
||||
if (animationCounter % animationSpeed == 0)
|
||||
animation_counter_++;
|
||||
if (animation_counter_ % animation_speed_ == 0)
|
||||
{
|
||||
animate();
|
||||
}
|
||||
}
|
||||
|
||||
// Establece el rectangulo de la textura que se va a pintar
|
||||
void Sprite::setClip(SDL_Rect clip)
|
||||
void Sprite::setClip(SDL_FRect clip)
|
||||
{
|
||||
this->clip = clip;
|
||||
clip_ = clip;
|
||||
}
|
||||
|
||||
// Establece el tamaño del sprite
|
||||
void Sprite::setSize(int w, int h)
|
||||
{
|
||||
this->pos.w = w;
|
||||
this->pos.h = h;
|
||||
pos_.w = w;
|
||||
pos_.h = h;
|
||||
}
|
||||
|
||||
// Anima el sprite
|
||||
void Sprite::animate()
|
||||
{
|
||||
frame = (frame + 1) % numFrames;
|
||||
clip.x = frame * pos.w;
|
||||
frame_ = (frame_ + 1) % num_frames_;
|
||||
clip_.x = frame_ * pos_.w;
|
||||
}
|
||||
|
||||
// Modulación de color
|
||||
void Sprite::setColor(int r, int g, int b)
|
||||
{
|
||||
texture->setColor(r, g, b);
|
||||
texture_->setColor(r, g, b);
|
||||
}
|
||||
|
||||
// Cambia la velocidad de la animación
|
||||
void Sprite::setAnimationSpeed(int value)
|
||||
{
|
||||
animationSpeed = value;
|
||||
animationCounter = 0;
|
||||
animation_speed_ = value;
|
||||
animation_counter_ = 0;
|
||||
}
|
||||
Reference in New Issue
Block a user