1
Graphics / Fade in - fade out transition function
« on: August 31, 2018, 02:28:09 pm »
Hello there!
I have a rectangle shape with the size of the window.
I'm trying to create a transition effect that fades in the rectangle and then fades out when the first fade is fully completed.
This whole effect starts when someBool == superiorBool::True and ends when someBool == superiorBool::Unitialized.
For some reasons it doesn't work. Any ideas?
Thanks in advance!
I have a rectangle shape with the size of the window.
I'm trying to create a transition effect that fades in the rectangle and then fades out when the first fade is fully completed.
This whole effect starts when someBool == superiorBool::True and ends when someBool == superiorBool::Unitialized.
void Application::transition()
{
transitionRectangle.setFillColor(sf::Color(0,0,0, transitionRectangleAlphaChannel)); // transitionRectangleAlphaChannel is initialized as 0 by default
if (transitionClock.getElapsedTime().asSeconds() > 0.1f && transitionRectangleAlphaChannel < 255.f && someBool == superiorBool::True)
{
transitionClock.restart();
transitionRectangleAlphaChannel += 5;
}
else if (transitionClock.getElapsedTime().asSeconds() > 0.1f && transitionRectangleAlphaChannel > 0.f && someBool == superiorBool::False)
{
transitionClock.restart();
transitionRectangleAlphaChannel -= 5;
}
if (someBool == superiorBool::True && transitionRectangleAlphaChannel == 255)
{
someBool = superiorBool::False;
}
else if (someBool == superiorBool::False && transitionRectangleAlphaChannel == 0)
{
someBool = superiorBool::Uninitialized;
}
{
transitionRectangle.setFillColor(sf::Color(0,0,0, transitionRectangleAlphaChannel)); // transitionRectangleAlphaChannel is initialized as 0 by default
if (transitionClock.getElapsedTime().asSeconds() > 0.1f && transitionRectangleAlphaChannel < 255.f && someBool == superiorBool::True)
{
transitionClock.restart();
transitionRectangleAlphaChannel += 5;
}
else if (transitionClock.getElapsedTime().asSeconds() > 0.1f && transitionRectangleAlphaChannel > 0.f && someBool == superiorBool::False)
{
transitionClock.restart();
transitionRectangleAlphaChannel -= 5;
}
if (someBool == superiorBool::True && transitionRectangleAlphaChannel == 255)
{
someBool = superiorBool::False;
}
else if (someBool == superiorBool::False && transitionRectangleAlphaChannel == 0)
{
someBool = superiorBool::Uninitialized;
}
For some reasons it doesn't work. Any ideas?
Thanks in advance!