trabajando en el movimiento easing del marcador

This commit is contained in:
2022-09-23 14:09:36 +02:00
parent 52d0c182f3
commit afe5b52b6b
4 changed files with 336 additions and 8 deletions

View File

@@ -22,7 +22,10 @@ ScoreBoard::ScoreBoard(SDL_Renderer *renderer, Asset *asset, board_t *board)
SDL_SetTextureBlendMode(layer, SDL_BLENDMODE_BLEND);
// Inicializa las variables
rect = {SCOREBOARD_X, SCOREBOARD_Y, SCOREBOARD_WIDTH, SCOREBOARD_HEIGHT};
counter = 0;
movingCounter = 0;
fadingCounter = 0;
state = sb_hide;
}
@@ -39,6 +42,11 @@ ScoreBoard::~ScoreBoard()
// Dibuja el marcador en la textura
void ScoreBoard::fillTexture()
{
if (state == sb_hide)
{
return;
}
// Cambia el puntero del renderizador a la textura y la limpia
SDL_SetRenderTarget(renderer, layer);
SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00);
@@ -72,21 +80,67 @@ void ScoreBoard::render()
{
return;
}
// Dibuja la textura con el marcador en pantalla
SDL_Rect rect = {SCOREBOARD_X, SCOREBOARD_Y, SCOREBOARD_WIDTH, SCOREBOARD_HEIGHT};
// SDL_Rect rect = {SCOREBOARD_X, SCOREBOARD_Y, SCOREBOARD_WIDTH, SCOREBOARD_HEIGHT};
SDL_RenderCopy(renderer, layer, NULL, &rect);
}
// Actualiza las variables del objeto
void ScoreBoard::update()
{
if (counter == 200)
{
state = sb_show;
}
else
if (state == sb_hide)
{
counter++;
if (counter == 200)
{
state = sb_showing;
rect.y = SCOREBOARD_Y - SCOREBOARD_HEIGHT;
}
}
else if (state == sb_showing)
{
movingCounter++;
fadingCounter++;
// float step = ((float)fadingCounter / (float)SCOREBOARD_HEIGHT);
auto easingFunction = getEasingFunction(EaseOutSine);
auto step = easingFunction(((float)fadingCounter / (float)SCOREBOARD_HEIGHT));
int alpha = 0 + ((255 - 0) * step);
int pos = -32 + ((0 + 32) * step);
rect.y = pos;
SDL_SetTextureAlphaMod(layer, alpha);
if (rect.y == SCOREBOARD_Y)
{
state = sb_show;
SDL_SetTextureAlphaMod(layer, 255);
}
}
else if (state == sb_hiding)
{
movingCounter--;
fadingCounter--;
auto easingFunction = getEasingFunction(EaseOutSine);
auto step = easingFunction(((float)fadingCounter / (float)SCOREBOARD_HEIGHT));
int alpha = 0 + ((255 - 0) * step);
int pos = -32 + ((0 + 32) * step);
rect.y = pos;
SDL_SetTextureAlphaMod(layer, alpha);
if (rect.y == SCOREBOARD_Y - SCOREBOARD_HEIGHT)
{
state = sb_hide;
counter = 0;
movingCounter = 0;
fadingCounter = 0;
SDL_SetTextureAlphaMod(layer, 255);
}
}
}
@@ -100,6 +154,19 @@ void ScoreBoard::reLoadTexture()
// Resetea el tiempo de aparición del marcador
void ScoreBoard::reset()
{
counter = 0;
state = sb_hide;
if (state == sb_hide)
{
counter = 0;
}
else
{
state = sb_hiding;
}
}
// Devuelve el rectangulo con la posición del marcador
SDL_Rect ScoreBoard::getRect()
{
return rect;
}