Magic_Game/core/Transition/TransitionFade.cpp

62 lines
1.2 KiB
C++
Raw Normal View History

2018-04-21 21:24:46 +08:00
#include "..\e2dtransition.h"
#include "..\e2dnode.h"
2018-04-17 01:11:56 +08:00
e2d::TransitionFade::TransitionFade(double duration)
: TransitionBase(0)
2018-04-17 01:11:56 +08:00
, m_fFadeOutDuration(max(duration / 2, 0))
, m_fFadeInDuration(max(duration / 2, 0))
, m_bFadeOutTransioning(true)
{
}
2018-04-17 01:11:56 +08:00
e2d::TransitionFade::TransitionFade(double fadeOutDuration, double fadeInDuration)
: TransitionBase(0)
2018-04-17 01:11:56 +08:00
, m_fFadeOutDuration(max(fadeOutDuration, 0))
, m_fFadeInDuration(max(fadeInDuration, 0))
, m_bFadeOutTransioning(true)
{
2018-04-17 01:11:56 +08:00
}
2018-01-30 16:45:38 +08:00
2018-04-17 11:41:33 +08:00
void e2d::TransitionFade::_init(Scene * prev, Scene * next)
{
TransitionBase::_init(prev, next);
2018-04-17 11:41:33 +08:00
if (m_pPrevScene)
{
m_bFadeOutTransioning = true;
m_fDuration = m_fFadeOutDuration;
}
else
{
m_bFadeOutTransioning = false;
m_fDuration = m_fFadeInDuration;
}
m_sPrevLayerParam.opacity = 1;
m_sNextLayerParam.opacity = 0;
}
2018-04-17 01:11:56 +08:00
void e2d::TransitionFade::_updateCustom()
{
2018-01-30 16:45:38 +08:00
if (m_bFadeOutTransioning)
{
2018-04-17 01:11:56 +08:00
m_sPrevLayerParam.opacity = float(1 - m_fRateOfProgress);
2018-01-30 16:45:38 +08:00
if (m_fRateOfProgress >= 1)
{
2018-01-30 16:45:38 +08:00
m_bFadeOutTransioning = false;
2018-04-17 01:11:56 +08:00
m_fDuration = m_fFadeInDuration;
m_fLast = Time::getTotalTime();
}
2018-01-30 16:45:38 +08:00
}
else
{
2018-04-17 01:11:56 +08:00
m_sNextLayerParam.opacity = float(m_fRateOfProgress);
2018-01-30 16:45:38 +08:00
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::_reset()
{
}