Trabajando en las animaciones de las notificaciones
This commit is contained in:
@@ -43,19 +43,22 @@ void Notify::update()
|
||||
{
|
||||
notifications.at(i).counter++;
|
||||
|
||||
const int height = notifications.at(i).texture->getHeight();
|
||||
const int halfDesp = text->getCharacterSize() / 2;
|
||||
|
||||
// Comprueba los estados
|
||||
if (notifications.at(i).state == ns_rising)
|
||||
{
|
||||
const float step = (notifications.at(i).counter / (float)notifications.at(i).texture->getHeight());
|
||||
const float step = ((float)notifications.at(i).counter / (height + halfDesp));
|
||||
const int alpha = 255 * step;
|
||||
|
||||
notifications.at(i).rect.y++;
|
||||
//notifications.at(i).texture->setAlpha(alpha);
|
||||
notifications.at(i).texture->setAlpha(alpha);
|
||||
|
||||
if (notifications.at(i).rect.y == 0)
|
||||
if (notifications.at(i).rect.y == 0 + halfDesp)
|
||||
{
|
||||
notifications.at(i).state = ns_stay;
|
||||
//notifications.at(i).texture->setAlpha(255);
|
||||
notifications.at(i).texture->setAlpha(255);
|
||||
notifications.at(i).counter = 0;
|
||||
}
|
||||
}
|
||||
@@ -71,13 +74,13 @@ void Notify::update()
|
||||
else if (notifications.at(i).state == ns_vanishing)
|
||||
{
|
||||
|
||||
const float step = (notifications.at(i).counter / (float)notifications.at(i).texture->getHeight());
|
||||
const float step = (notifications.at(i).counter / (float)height);
|
||||
const int alpha = 255 * step;
|
||||
|
||||
notifications.at(i).rect.y--;
|
||||
//notifications.at(i).texture->setAlpha(alpha);
|
||||
notifications.at(i).texture->setAlpha(alpha);
|
||||
|
||||
if (notifications.at(i).rect.y == -notifications.at(i).texture->getHeight())
|
||||
if (notifications.at(i).rect.y == -height)
|
||||
{
|
||||
notifications.at(i).state = ns_finished;
|
||||
}
|
||||
@@ -110,6 +113,7 @@ void Notify::showText(std::string text)
|
||||
const int width = this->text->lenght(text) + (this->text->getCharacterSize() * 2);
|
||||
const int height = this->text->getCharacterSize() * 2;
|
||||
const int desp = this->text->getCharacterSize();
|
||||
const int halfDesp = desp / 2;
|
||||
|
||||
// Crea la notificacion
|
||||
notification_t n;
|
||||
@@ -118,7 +122,7 @@ void Notify::showText(std::string text)
|
||||
n.counter = 0;
|
||||
n.state = ns_rising;
|
||||
n.text = text;
|
||||
n.rect = {0, -height, width, height};
|
||||
n.rect = {halfDesp, -height, width, height};
|
||||
|
||||
// Crea la textura
|
||||
n.texture = new Texture(renderer);
|
||||
@@ -127,7 +131,7 @@ void Notify::showText(std::string text)
|
||||
SDL_SetRenderDrawColor(renderer, bgColor.r, bgColor.g, bgColor.b, 255);
|
||||
SDL_RenderClear(renderer);
|
||||
n.texture->setBlendMode(SDL_BLENDMODE_BLEND);
|
||||
this->text->writeDX(TXT_CENTER | TXT_STROKE, width / 2, desp / 2, text, 1, {255, 255, 255}, 1, {0, 0, 0});
|
||||
this->text->writeDX(TXT_CENTER | TXT_STROKE, width / 2, halfDesp, text, 1, {255, 255, 255}, 1, {0, 0, 0});
|
||||
|
||||
// Crea el sprite
|
||||
n.sprite = new Sprite(n.rect, n.texture, renderer);
|
||||
|
||||
Reference in New Issue
Block a user