Capa de fondo con posibilidad de scroll

This commit is contained in:
2022-09-23 17:32:09 +02:00
parent afe5b52b6b
commit eac0236c60
10 changed files with 62 additions and 20 deletions

View File

@@ -24,7 +24,6 @@ ScoreBoard::ScoreBoard(SDL_Renderer *renderer, Asset *asset, board_t *board)
// Inicializa las variables
rect = {SCOREBOARD_X, SCOREBOARD_Y, SCOREBOARD_WIDTH, SCOREBOARD_HEIGHT};
counter = 0;
movingCounter = 0;
fadingCounter = 0;
state = sb_hide;
}
@@ -101,16 +100,12 @@ void ScoreBoard::update()
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);
const float step = ((float)fadingCounter / (float)SCOREBOARD_HEIGHT);
const int alpha = 255 * step;
rect.y = pos;
rect.y++;
SDL_SetTextureAlphaMod(layer, alpha);
if (rect.y == SCOREBOARD_Y)
@@ -122,22 +117,18 @@ void ScoreBoard::update()
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);
const float step = ((float)fadingCounter / (float)SCOREBOARD_HEIGHT);
const int alpha = 255 * step;
rect.y = pos;
rect.y--;
SDL_SetTextureAlphaMod(layer, alpha);
if (rect.y == SCOREBOARD_Y - SCOREBOARD_HEIGHT)
{
state = sb_hide;
counter = 0;
movingCounter = 0;
fadingCounter = 0;
SDL_SetTextureAlphaMod(layer, 255);
}