Magic_Game/core/Transition/ETransitionFade.cpp

57 lines
1.1 KiB
C++
Raw Normal View History

#include "..\etransitions.h"
#include "..\enodes.h"
2018-02-27 21:07:43 +08:00
e2d::TransitionFade::TransitionFade(double fadeOutDuration, double fadeInDuration)
: Transition(0)
2018-01-30 16:45:38 +08:00
, m_fFadeOutDuration(fadeOutDuration)
, m_fFadeInDuration(fadeInDuration)
, m_bFadeOutTransioning(true)
{
2018-01-30 16:45:38 +08:00
m_fDuration = max(m_fFadeOutDuration, 0);
}
void e2d::TransitionFade::_update()
{
2018-01-30 16:45:38 +08:00
this->_calcRateOfProgress();
if (m_bFadeOutTransioning)
{
2018-01-30 16:45:38 +08:00
m_pPrevScene->getRoot()->setOpacity(1 - m_fRateOfProgress);
if (m_fRateOfProgress >= 1)
{
2018-01-30 16:45:38 +08:00
m_bFadeOutTransioning = false;
m_fDuration = max(m_fFadeInDuration, 0);
m_fLast = Time::getTotalTime();
}
2018-01-30 16:45:38 +08:00
}
else
{
m_pNextScene->getRoot()->setOpacity(m_fRateOfProgress);
if (m_fRateOfProgress >= 1)
2017-10-21 19:09:31 +08:00
{
2018-01-30 16:45:38 +08:00
this->_stop();
2017-10-21 19:09:31 +08:00
}
}
}
void e2d::TransitionFade::_init()
{
if (m_pPrevScene)
{
m_bFadeOutTransioning = true;
m_pPrevScene->getRoot()->setOpacity(1);
}
else
{
m_bFadeOutTransioning = false;
2018-01-30 16:45:38 +08:00
m_fDuration = m_fFadeInDuration;
}
m_pNextScene->getRoot()->setOpacity(0);
}
void e2d::TransitionFade::_reset()
{
if (m_pPrevScene) m_pPrevScene->getRoot()->setOpacity(1);
m_pNextScene->getRoot()->setOpacity(1);
}