新增Action生成器和Transition生成器
This commit is contained in:
parent
69f6172fa0
commit
904218e74d
|
|
@ -1,106 +1,133 @@
|
|||
#include "..\e2daction.h"
|
||||
#include "..\e2dmanager.h"
|
||||
|
||||
e2d::Action::Action()
|
||||
: m_bRunning(false)
|
||||
, m_bEnding(false)
|
||||
, m_bInit(false)
|
||||
, m_pTarget(nullptr)
|
||||
, m_pParentScene(nullptr)
|
||||
, m_fLast(0)
|
||||
e2d::ActionMoveBy * e2d::Action::MoveBy(double duration, Vector vector)
|
||||
{
|
||||
ActionManager::__add(this);
|
||||
return new (std::nothrow) ActionMoveBy(duration, vector);
|
||||
}
|
||||
|
||||
e2d::Action::~Action()
|
||||
e2d::ActionMoveTo * e2d::Action::MoveTo(double duration, Point pos)
|
||||
{
|
||||
return new (std::nothrow) ActionMoveTo(duration, pos);
|
||||
}
|
||||
|
||||
bool e2d::Action::isRunning()
|
||||
e2d::ActionScaleBy * e2d::Action::ScaleBy(double duration, double scale)
|
||||
{
|
||||
return m_bRunning;
|
||||
return new (std::nothrow) ActionScaleBy(duration, scale);
|
||||
}
|
||||
|
||||
bool e2d::Action::_isEnding()
|
||||
e2d::ActionScaleBy * e2d::Action::ScaleBy(double duration, double scaleX, double scaleY)
|
||||
{
|
||||
return m_bEnding;
|
||||
return new (std::nothrow) ActionScaleBy(duration, scaleX, scaleY);
|
||||
}
|
||||
|
||||
void e2d::Action::setTarget(Node* pTarget)
|
||||
e2d::ActionScaleTo * e2d::Action::ScaleTo(double duration, double scale)
|
||||
{
|
||||
if (pTarget)
|
||||
return new (std::nothrow) ActionScaleTo(duration, scale);
|
||||
}
|
||||
|
||||
e2d::ActionScaleTo * e2d::Action::ScaleTo(double duration, double scaleX, double scaleY)
|
||||
{
|
||||
return new (std::nothrow) ActionScaleTo(duration, scaleX, scaleY);
|
||||
}
|
||||
|
||||
e2d::ActionOpacityBy * e2d::Action::OpacityBy(double duration, double opacity)
|
||||
{
|
||||
return new (std::nothrow) ActionOpacityBy(duration, opacity);
|
||||
}
|
||||
|
||||
e2d::ActionOpacityTo * e2d::Action::OpacityTo(double duration, double opacity)
|
||||
{
|
||||
return new (std::nothrow) ActionOpacityTo(duration, opacity);
|
||||
}
|
||||
|
||||
e2d::ActionFadeIn * e2d::Action::FadeIn(double duration)
|
||||
{
|
||||
return new (std::nothrow) ActionFadeIn(duration);
|
||||
}
|
||||
|
||||
e2d::ActionFadeOut * e2d::Action::FadeOut(double duration)
|
||||
{
|
||||
return new (std::nothrow) ActionFadeOut(duration);
|
||||
}
|
||||
|
||||
e2d::ActionRotateBy * e2d::Action::RotateBy(double duration, double rotation)
|
||||
{
|
||||
return new (std::nothrow) ActionRotateBy(duration, rotation);
|
||||
}
|
||||
|
||||
e2d::ActionRotateTo * e2d::Action::RotateTo(double duration, double rotation)
|
||||
{
|
||||
return new (std::nothrow) ActionRotateTo(duration, rotation);
|
||||
}
|
||||
|
||||
e2d::ActionTwo * e2d::Action::Two(ActionBase * pActionFirst, ActionBase * pActionSecond, bool bAtSameTime)
|
||||
{
|
||||
return new (std::nothrow) ActionTwo(pActionFirst, pActionSecond, bAtSameTime);
|
||||
}
|
||||
|
||||
e2d::ActionDelay * e2d::Action::Delay(double duration)
|
||||
{
|
||||
return new (std::nothrow) ActionDelay(duration);
|
||||
}
|
||||
|
||||
e2d::ActionLoop * e2d::Action::Loop(ActionBase * action, int times)
|
||||
{
|
||||
return new (std::nothrow) ActionLoop(action, times);
|
||||
}
|
||||
|
||||
e2d::ActionFunc * e2d::Action::Func(Function func)
|
||||
{
|
||||
return new (std::nothrow) ActionFunc(func);
|
||||
}
|
||||
|
||||
#ifdef HIGHER_THAN_VS2012
|
||||
|
||||
e2d::ActionSequence * e2d::Action::Sequence(const InitList<ActionBase*>& vActions)
|
||||
{
|
||||
return new (std::nothrow) ActionSequence(vActions);
|
||||
}
|
||||
|
||||
e2d::Animation * e2d::Action::Animation(double interval, const InitList<Image*>& vFrames)
|
||||
{
|
||||
return new (std::nothrow) e2d::Animation(interval, vFrames);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
e2d::ActionSequence * e2d::Action::Sequence(int number, ActionBase * action1, ...)
|
||||
{
|
||||
auto action = new (std::nothrow) ActionSequence();
|
||||
if (action)
|
||||
{
|
||||
m_bRunning = true;
|
||||
m_pTarget = pTarget;
|
||||
this->reset();
|
||||
}
|
||||
}
|
||||
ActionBase ** ppAction = &action1;
|
||||
|
||||
void e2d::Action::resume()
|
||||
{
|
||||
m_bRunning = true;
|
||||
m_fLast = Time::getTotalTime();
|
||||
}
|
||||
|
||||
void e2d::Action::pause()
|
||||
{
|
||||
m_bRunning = false;
|
||||
}
|
||||
|
||||
void e2d::Action::stop()
|
||||
{
|
||||
m_bEnding = true;
|
||||
}
|
||||
|
||||
e2d::String e2d::Action::getName() const
|
||||
{
|
||||
return m_sName;
|
||||
}
|
||||
|
||||
void e2d::Action::setName(String name)
|
||||
{
|
||||
m_sName = name;
|
||||
}
|
||||
|
||||
e2d::Action * e2d::Action::reverse() const
|
||||
{
|
||||
WARN_IF(true, "Action cannot be reversed!");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
e2d::Node * e2d::Action::getTarget()
|
||||
{
|
||||
return m_pTarget;
|
||||
}
|
||||
|
||||
void e2d::Action::destroy()
|
||||
{
|
||||
ActionManager::__remove(this);
|
||||
}
|
||||
|
||||
void e2d::Action::_init()
|
||||
{
|
||||
m_bInit = true;
|
||||
// ¼Ç¼µ±Ç°Ê±¼ä
|
||||
m_fLast = Time::getTotalTime();
|
||||
}
|
||||
|
||||
void e2d::Action::_update()
|
||||
{
|
||||
if (!m_bInit)
|
||||
while (number > 0)
|
||||
{
|
||||
_init();
|
||||
WARN_IF((*ppAction) == nullptr, "ActionSequence NULL pointer exception!");
|
||||
action->add(*ppAction);
|
||||
ppAction++;
|
||||
number--;
|
||||
}
|
||||
}
|
||||
return action;
|
||||
}
|
||||
|
||||
void e2d::Action::reset()
|
||||
e2d::Animation * e2d::Action::Animation(double interval, int number, Image * frame, ...)
|
||||
{
|
||||
m_bInit = false;
|
||||
m_bEnding = false;
|
||||
m_fLast = Time::getTotalTime();
|
||||
auto animation = new (std::nothrow) e2d::Animation(interval);
|
||||
if (animation)
|
||||
{
|
||||
Image ** ppImage = &frame;
|
||||
|
||||
while (number > 0)
|
||||
{
|
||||
WARN_IF((*ppImage) == nullptr, "Animation NULL pointer exception!");
|
||||
animation->add(*ppImage);
|
||||
ppImage++;
|
||||
number--;
|
||||
}
|
||||
}
|
||||
return animation;
|
||||
}
|
||||
|
||||
void e2d::Action::_resetTime()
|
||||
{
|
||||
m_fLast = Time::getTotalTime();
|
||||
}
|
||||
#endif
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
#include "..\e2daction.h"
|
||||
#include "..\e2dmanager.h"
|
||||
|
||||
e2d::ActionBase::ActionBase()
|
||||
: m_bRunning(false)
|
||||
, m_bEnding(false)
|
||||
, m_bInit(false)
|
||||
, m_pTarget(nullptr)
|
||||
, m_pParentScene(nullptr)
|
||||
, m_fLast(0)
|
||||
{
|
||||
ActionManager::__add(this);
|
||||
}
|
||||
|
||||
e2d::ActionBase::~ActionBase()
|
||||
{
|
||||
}
|
||||
|
||||
bool e2d::ActionBase::isRunning()
|
||||
{
|
||||
return m_bRunning;
|
||||
}
|
||||
|
||||
bool e2d::ActionBase::_isEnding()
|
||||
{
|
||||
return m_bEnding;
|
||||
}
|
||||
|
||||
void e2d::ActionBase::setTarget(Node* pTarget)
|
||||
{
|
||||
if (pTarget)
|
||||
{
|
||||
m_bRunning = true;
|
||||
m_pTarget = pTarget;
|
||||
this->reset();
|
||||
}
|
||||
}
|
||||
|
||||
void e2d::ActionBase::resume()
|
||||
{
|
||||
m_bRunning = true;
|
||||
m_fLast = Time::getTotalTime();
|
||||
}
|
||||
|
||||
void e2d::ActionBase::pause()
|
||||
{
|
||||
m_bRunning = false;
|
||||
}
|
||||
|
||||
void e2d::ActionBase::stop()
|
||||
{
|
||||
m_bEnding = true;
|
||||
}
|
||||
|
||||
e2d::String e2d::ActionBase::getName() const
|
||||
{
|
||||
return m_sName;
|
||||
}
|
||||
|
||||
void e2d::ActionBase::setName(String name)
|
||||
{
|
||||
m_sName = name;
|
||||
}
|
||||
|
||||
e2d::ActionBase * e2d::ActionBase::reverse() const
|
||||
{
|
||||
WARN_IF(true, "ActionBase cannot be reversed!");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
e2d::Node * e2d::ActionBase::getTarget()
|
||||
{
|
||||
return m_pTarget;
|
||||
}
|
||||
|
||||
void e2d::ActionBase::destroy()
|
||||
{
|
||||
ActionManager::__remove(this);
|
||||
}
|
||||
|
||||
void e2d::ActionBase::_init()
|
||||
{
|
||||
m_bInit = true;
|
||||
// ¼Ç¼µ±Ç°Ê±¼ä
|
||||
m_fLast = Time::getTotalTime();
|
||||
}
|
||||
|
||||
void e2d::ActionBase::_update()
|
||||
{
|
||||
if (!m_bInit)
|
||||
{
|
||||
_init();
|
||||
}
|
||||
}
|
||||
|
||||
void e2d::ActionBase::reset()
|
||||
{
|
||||
m_bInit = false;
|
||||
m_bEnding = false;
|
||||
m_fLast = Time::getTotalTime();
|
||||
}
|
||||
|
||||
void e2d::ActionBase::_resetTime()
|
||||
{
|
||||
m_fLast = Time::getTotalTime();
|
||||
}
|
||||
|
|
@ -12,12 +12,12 @@ e2d::ActionDelay * e2d::ActionDelay::clone() const
|
|||
|
||||
void e2d::ActionDelay::_init()
|
||||
{
|
||||
Action::_init();
|
||||
ActionBase::_init();
|
||||
}
|
||||
|
||||
void e2d::ActionDelay::_update()
|
||||
{
|
||||
Action::_update();
|
||||
ActionBase::_update();
|
||||
// 判断时间间隔是否足够
|
||||
if ((Time::getTotalTime() - m_fLast) >= m_fDelayTime)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8,12 +8,12 @@ e2d::ActionGradual::ActionGradual(double duration)
|
|||
|
||||
void e2d::ActionGradual::_init()
|
||||
{
|
||||
Action::_init();
|
||||
ActionBase::_init();
|
||||
}
|
||||
|
||||
void e2d::ActionGradual::_update()
|
||||
{
|
||||
Action::_update();
|
||||
ActionBase::_update();
|
||||
// 判断时间间隔是否足够
|
||||
if (m_fDuration == 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
#include "..\e2daction.h"
|
||||
#include "..\e2dmanager.h"
|
||||
|
||||
e2d::ActionLoop::ActionLoop(Action * action, int times /* = -1 */)
|
||||
e2d::ActionLoop::ActionLoop(ActionBase * action, int times /* = -1 */)
|
||||
: m_pAction(action)
|
||||
, m_nTimes(0)
|
||||
, m_nTotalTimes(times)
|
||||
|
|
@ -21,14 +21,14 @@ e2d::ActionLoop * e2d::ActionLoop::clone() const
|
|||
|
||||
void e2d::ActionLoop::_init()
|
||||
{
|
||||
Action::_init();
|
||||
ActionBase::_init();
|
||||
m_pAction->m_pTarget = m_pTarget;
|
||||
m_pAction->_init();
|
||||
}
|
||||
|
||||
void e2d::ActionLoop::_update()
|
||||
{
|
||||
Action::_update();
|
||||
ActionBase::_update();
|
||||
|
||||
if (m_nTimes == m_nTotalTimes)
|
||||
{
|
||||
|
|
@ -42,14 +42,14 @@ void e2d::ActionLoop::_update()
|
|||
{
|
||||
m_nTimes++;
|
||||
|
||||
Action::reset();
|
||||
ActionBase::reset();
|
||||
m_pAction->reset();
|
||||
}
|
||||
}
|
||||
|
||||
void e2d::ActionLoop::reset()
|
||||
{
|
||||
Action::reset();
|
||||
ActionBase::reset();
|
||||
|
||||
m_pAction->reset();
|
||||
m_nTimes = 0;
|
||||
|
|
@ -57,7 +57,7 @@ void e2d::ActionLoop::reset()
|
|||
|
||||
void e2d::ActionLoop::destroy()
|
||||
{
|
||||
Action::destroy();
|
||||
ActionBase::destroy();
|
||||
SafeRelease(&m_pAction);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,16 +6,16 @@ e2d::ActionSequence::ActionSequence()
|
|||
}
|
||||
|
||||
#ifdef HIGHER_THAN_VS2012
|
||||
e2d::ActionSequence::ActionSequence(const InitList<Action*>& vActions)
|
||||
e2d::ActionSequence::ActionSequence(const InitList<ActionBase*>& vActions)
|
||||
: m_nActionIndex(0)
|
||||
{
|
||||
this->add(vActions);
|
||||
}
|
||||
#else
|
||||
e2d::ActionSequence::ActionSequence(int number, Action * action1, ...) :
|
||||
e2d::ActionSequence::ActionSequence(int number, ActionBase * action1, ...) :
|
||||
m_nActionIndex(0)
|
||||
{
|
||||
Action ** ppAction = &action1;
|
||||
ActionBase ** ppAction = &action1;
|
||||
|
||||
while (number > 0)
|
||||
{
|
||||
|
|
@ -33,7 +33,7 @@ e2d::ActionSequence::~ActionSequence()
|
|||
|
||||
void e2d::ActionSequence::_init()
|
||||
{
|
||||
Action::_init();
|
||||
ActionBase::_init();
|
||||
// ½«ËùÓж¯×÷ÓëÄ¿±ê°ó¶¨
|
||||
if (m_pTarget)
|
||||
{
|
||||
|
|
@ -48,7 +48,7 @@ void e2d::ActionSequence::_init()
|
|||
|
||||
void e2d::ActionSequence::destroy()
|
||||
{
|
||||
Action::destroy();
|
||||
ActionBase::destroy();
|
||||
for (auto action : m_vActions)
|
||||
{
|
||||
SafeRelease(&action);
|
||||
|
|
@ -57,7 +57,7 @@ void e2d::ActionSequence::destroy()
|
|||
|
||||
void e2d::ActionSequence::_update()
|
||||
{
|
||||
Action::_update();
|
||||
ActionBase::_update();
|
||||
|
||||
auto &action = m_vActions[m_nActionIndex];
|
||||
action->_update();
|
||||
|
|
@ -78,7 +78,7 @@ void e2d::ActionSequence::_update()
|
|||
|
||||
void e2d::ActionSequence::reset()
|
||||
{
|
||||
Action::reset();
|
||||
ActionBase::reset();
|
||||
for (auto action : m_vActions)
|
||||
{
|
||||
action->reset();
|
||||
|
|
@ -94,7 +94,7 @@ void e2d::ActionSequence::_resetTime()
|
|||
}
|
||||
}
|
||||
|
||||
void e2d::ActionSequence::add(Action * action)
|
||||
void e2d::ActionSequence::add(ActionBase * action)
|
||||
{
|
||||
if (action)
|
||||
{
|
||||
|
|
@ -104,7 +104,7 @@ void e2d::ActionSequence::add(Action * action)
|
|||
}
|
||||
|
||||
#ifdef HIGHER_THAN_VS2012
|
||||
void e2d::ActionSequence::add(const InitList<Action*>& vActions)
|
||||
void e2d::ActionSequence::add(const InitList<ActionBase*>& vActions)
|
||||
{
|
||||
for (const auto &action : vActions)
|
||||
{
|
||||
|
|
@ -112,9 +112,9 @@ void e2d::ActionSequence::add(const InitList<Action*>& vActions)
|
|||
}
|
||||
}
|
||||
#else
|
||||
void e2d::ActionSequence::add(int number, Action * action, ...)
|
||||
void e2d::ActionSequence::add(int number, ActionBase * action, ...)
|
||||
{
|
||||
Action ** ppAction = &action;
|
||||
ActionBase ** ppAction = &action;
|
||||
|
||||
while (number > 0)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#include "..\e2daction.h"
|
||||
|
||||
e2d::ActionTwo::ActionTwo(Action * pActionFirst, Action * pActionSecond, bool bAtSameTime/* = false*/)
|
||||
e2d::ActionTwo::ActionTwo(ActionBase * pActionFirst, ActionBase * pActionSecond, bool bAtSameTime/* = false*/)
|
||||
: m_pFirstAction(pActionFirst)
|
||||
, m_pSecondAction(pActionSecond)
|
||||
, m_bAtSameTime(bAtSameTime)
|
||||
|
|
@ -33,7 +33,7 @@ e2d::ActionTwo * e2d::ActionTwo::reverse(bool actionReverse) const
|
|||
|
||||
void e2d::ActionTwo::_init()
|
||||
{
|
||||
Action::_init();
|
||||
ActionBase::_init();
|
||||
m_pFirstAction->m_pTarget = m_pTarget;
|
||||
m_pSecondAction->m_pTarget = m_pTarget;
|
||||
|
||||
|
|
@ -43,7 +43,7 @@ void e2d::ActionTwo::_init()
|
|||
|
||||
void e2d::ActionTwo::_update()
|
||||
{
|
||||
Action::_update();
|
||||
ActionBase::_update();
|
||||
|
||||
if (!m_pFirstAction->_isEnding())
|
||||
{
|
||||
|
|
@ -75,7 +75,7 @@ void e2d::ActionTwo::_update()
|
|||
|
||||
void e2d::ActionTwo::reset()
|
||||
{
|
||||
Action::reset();
|
||||
ActionBase::reset();
|
||||
|
||||
m_pFirstAction->reset();
|
||||
m_pSecondAction->reset();
|
||||
|
|
@ -83,7 +83,7 @@ void e2d::ActionTwo::reset()
|
|||
|
||||
void e2d::ActionTwo::destroy()
|
||||
{
|
||||
Action::destroy();
|
||||
ActionBase::destroy();
|
||||
SafeRelease(&m_pFirstAction);
|
||||
SafeRelease(&m_pSecondAction);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,12 +73,12 @@ void e2d::Animation::setInterval(double interval)
|
|||
|
||||
void e2d::Animation::_init()
|
||||
{
|
||||
Action::_init();
|
||||
ActionBase::_init();
|
||||
}
|
||||
|
||||
void e2d::Animation::_update()
|
||||
{
|
||||
Action::_update();
|
||||
ActionBase::_update();
|
||||
|
||||
if (m_pTarget == nullptr)
|
||||
{
|
||||
|
|
@ -105,13 +105,13 @@ void e2d::Animation::_update()
|
|||
|
||||
void e2d::Animation::reset()
|
||||
{
|
||||
Action::reset();
|
||||
ActionBase::reset();
|
||||
m_nFrameIndex = 0;
|
||||
}
|
||||
|
||||
void e2d::Animation::destroy()
|
||||
{
|
||||
Action::destroy();
|
||||
ActionBase::destroy();
|
||||
for (auto frame : m_vFrames)
|
||||
{
|
||||
SafeRelease(&frame);
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
#include "..\e2dmanager.h"
|
||||
#include "..\e2daction.h"
|
||||
|
||||
static std::vector<e2d::Action*> s_vActions;
|
||||
static std::vector<e2d::Action*> s_vRunningActions;
|
||||
static std::vector<e2d::ActionBase*> s_vActions;
|
||||
static std::vector<e2d::ActionBase*> s_vRunningActions;
|
||||
|
||||
|
||||
void e2d::ActionManager::__update()
|
||||
|
|
@ -33,7 +33,7 @@ void e2d::ActionManager::__update()
|
|||
}
|
||||
}
|
||||
|
||||
void e2d::ActionManager::__add(Action * pAction)
|
||||
void e2d::ActionManager::__add(ActionBase * pAction)
|
||||
{
|
||||
if (pAction)
|
||||
{
|
||||
|
|
@ -49,7 +49,7 @@ void e2d::ActionManager::__add(Action * pAction)
|
|||
}
|
||||
}
|
||||
|
||||
void e2d::ActionManager::__remove(Action * pAction)
|
||||
void e2d::ActionManager::__remove(ActionBase * pAction)
|
||||
{
|
||||
for (size_t i = 0; i < s_vActions.size(); i++)
|
||||
{
|
||||
|
|
@ -60,9 +60,9 @@ void e2d::ActionManager::__remove(Action * pAction)
|
|||
}
|
||||
}
|
||||
|
||||
void e2d::ActionManager::__startAction(Action * pAction, Node * pTargetNode)
|
||||
void e2d::ActionManager::__startAction(ActionBase * pAction, Node * pTargetNode)
|
||||
{
|
||||
WARN_IF(pAction == nullptr, "Action NULL pointer exception!");
|
||||
WARN_IF(pAction == nullptr, "ActionBase NULL pointer exception!");
|
||||
|
||||
if (pAction)
|
||||
{
|
||||
|
|
@ -201,9 +201,9 @@ void e2d::ActionManager::stopAll()
|
|||
}
|
||||
}
|
||||
|
||||
std::vector<e2d::Action*> e2d::ActionManager::get(String strActionName)
|
||||
std::vector<e2d::ActionBase*> e2d::ActionManager::get(String strActionName)
|
||||
{
|
||||
std::vector<Action*> vActions;
|
||||
std::vector<ActionBase*> vActions;
|
||||
for (auto action : s_vActions)
|
||||
{
|
||||
if (action->getName() == strActionName)
|
||||
|
|
@ -214,7 +214,7 @@ std::vector<e2d::Action*> e2d::ActionManager::get(String strActionName)
|
|||
return std::move(vActions);
|
||||
}
|
||||
|
||||
std::vector<e2d::Action*> e2d::ActionManager::getAll()
|
||||
std::vector<e2d::ActionBase*> e2d::ActionManager::getAll()
|
||||
{
|
||||
return s_vActions;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@
|
|||
|
||||
static e2d::Scene * s_pCurrScene = nullptr;
|
||||
static e2d::Scene * s_pNextScene = nullptr;
|
||||
static e2d::Transition * s_pTransition = nullptr;
|
||||
static e2d::TransitionBase * s_pTransition = nullptr;
|
||||
static std::stack<e2d::Scene*> s_SceneStack;
|
||||
|
||||
void e2d::SceneManager::enter(Scene * scene, Transition * transition /* = nullptr */, bool saveCurrentScene /* = true */)
|
||||
void e2d::SceneManager::enter(Scene * scene, TransitionBase * transition /* = nullptr */, bool saveCurrentScene /* = true */)
|
||||
{
|
||||
ASSERT(scene, "Next scene NULL pointer exception!");
|
||||
scene->retain();
|
||||
|
|
@ -35,7 +35,7 @@ void e2d::SceneManager::enter(Scene * scene, Transition * transition /* = nullpt
|
|||
}
|
||||
}
|
||||
|
||||
void e2d::SceneManager::back(Transition * transition /* = nullptr */)
|
||||
void e2d::SceneManager::back(TransitionBase * transition /* = nullptr */)
|
||||
{
|
||||
// 栈为空时,调用返回场景函数失败
|
||||
WARN_IF(s_SceneStack.size() == 0, "Scene stack is empty!");
|
||||
|
|
|
|||
|
|
@ -825,7 +825,7 @@ void e2d::Node::clearAllChildren()
|
|||
m_vChildren.clear();
|
||||
}
|
||||
|
||||
void e2d::Node::runAction(Action * action)
|
||||
void e2d::Node::runAction(ActionBase * action)
|
||||
{
|
||||
if (this != action->getTarget())
|
||||
{
|
||||
|
|
@ -882,7 +882,7 @@ void e2d::Node::stopAction(String strActionName)
|
|||
}
|
||||
}
|
||||
|
||||
e2d::Action * e2d::Node::getAction(String strActionName)
|
||||
e2d::ActionBase * e2d::Node::getAction(String strActionName)
|
||||
{
|
||||
auto actions = ActionManager::get(strActionName);
|
||||
for (auto action : actions)
|
||||
|
|
@ -895,9 +895,9 @@ e2d::Action * e2d::Node::getAction(String strActionName)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
std::vector<e2d::Action*> e2d::Node::getActions(String strActionName)
|
||||
std::vector<e2d::ActionBase*> e2d::Node::getActions(String strActionName)
|
||||
{
|
||||
std::vector<Action*>::iterator iter;
|
||||
std::vector<ActionBase*>::iterator iter;
|
||||
auto actions = ActionManager::get(strActionName);
|
||||
for (iter = actions.begin(); iter != actions.end();)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,135 +1,21 @@
|
|||
#include "..\e2dbase.h"
|
||||
#include "..\e2dtransition.h"
|
||||
#include "..\e2dnode.h"
|
||||
|
||||
e2d::Transition::Transition(double duration)
|
||||
: m_bEnd(false)
|
||||
, m_fLast(0)
|
||||
, m_fRateOfProgress(0)
|
||||
, m_pPrevScene(nullptr)
|
||||
, m_pNextScene(nullptr)
|
||||
, m_pPrevLayer(nullptr)
|
||||
, m_pNextLayer(nullptr)
|
||||
, m_sPrevLayerParam()
|
||||
, m_sNextLayerParam()
|
||||
e2d::TransitionFade * e2d::Transition::Fade(double duration)
|
||||
{
|
||||
m_fDuration = max(duration, 0);
|
||||
return new (std::nothrow) TransitionFade(duration);
|
||||
}
|
||||
|
||||
e2d::Transition::~Transition()
|
||||
e2d::TransitionFade * e2d::Transition::Fade(double fadeOutDuration, double fadeInDuration)
|
||||
{
|
||||
SafeReleaseInterface(&m_pPrevLayer);
|
||||
SafeReleaseInterface(&m_pNextLayer);
|
||||
return new (std::nothrow) TransitionFade(fadeOutDuration, fadeInDuration);
|
||||
}
|
||||
|
||||
bool e2d::Transition::isEnding()
|
||||
e2d::TransitionEmerge * e2d::Transition::Emerge(double duration)
|
||||
{
|
||||
return m_bEnd;
|
||||
return new (std::nothrow) TransitionEmerge(duration);
|
||||
}
|
||||
|
||||
void e2d::Transition::destroy()
|
||||
e2d::TransitionMove * e2d::Transition::Move(double duration, Direct direct)
|
||||
{
|
||||
SafeRelease(&m_pPrevScene);
|
||||
SafeRelease(&m_pNextScene);
|
||||
}
|
||||
|
||||
void e2d::Transition::_init(Scene * prev, Scene * next)
|
||||
{
|
||||
// 创建图层
|
||||
HRESULT hr = Renderer::getRenderTarget()->CreateLayer(&m_pNextLayer);
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = Renderer::getRenderTarget()->CreateLayer(&m_pPrevLayer);
|
||||
}
|
||||
|
||||
if (FAILED(hr))
|
||||
{
|
||||
ASSERT(false, "Create layer failed!");
|
||||
}
|
||||
|
||||
m_fLast = Time::getTotalTime();
|
||||
m_pPrevScene = prev;
|
||||
m_pNextScene = next;
|
||||
if (m_pPrevScene) m_pPrevScene->retain();
|
||||
if (m_pNextScene) m_pNextScene->retain();
|
||||
|
||||
m_WindowSize = Window::getSize();
|
||||
m_sPrevLayerParam = m_sNextLayerParam = D2D1::LayerParameters();
|
||||
}
|
||||
|
||||
void e2d::Transition::_update()
|
||||
{
|
||||
// 计算动画进度
|
||||
if (m_fDuration == 0)
|
||||
{
|
||||
m_fRateOfProgress = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_fRateOfProgress = min((Time::getTotalTime() - m_fLast) / m_fDuration, 1);
|
||||
}
|
||||
|
||||
this->_updateCustom();
|
||||
|
||||
// 更新场景内容
|
||||
if (m_pPrevScene)
|
||||
{
|
||||
m_pPrevScene->_update();
|
||||
}
|
||||
if (m_pNextScene)
|
||||
{
|
||||
m_pNextScene->_update();
|
||||
}
|
||||
}
|
||||
|
||||
void e2d::Transition::_render()
|
||||
{
|
||||
auto pRT = Renderer::getRenderTarget();
|
||||
|
||||
if (m_pPrevScene)
|
||||
{
|
||||
Point rootPos = m_pPrevScene->getRoot()->getPos();
|
||||
auto clipRect = D2D1::RectF(
|
||||
float(max(rootPos.x, 0)),
|
||||
float(max(rootPos.y, 0)),
|
||||
float(min(rootPos.x + m_WindowSize.width, m_WindowSize.width)),
|
||||
float(min(rootPos.y + m_WindowSize.height, m_WindowSize.height))
|
||||
);
|
||||
pRT->SetTransform(D2D1::Matrix3x2F::Identity());
|
||||
pRT->PushAxisAlignedClip(clipRect, D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
|
||||
pRT->PushLayer(m_sPrevLayerParam, m_pPrevLayer);
|
||||
|
||||
// 渲染场景
|
||||
m_pPrevScene->_render();
|
||||
|
||||
pRT->PopLayer();
|
||||
pRT->PopAxisAlignedClip();
|
||||
}
|
||||
|
||||
if (m_pNextScene)
|
||||
{
|
||||
Point rootPos = m_pNextScene->getRoot()->getPos();
|
||||
auto clipRect = D2D1::RectF(
|
||||
float(max(rootPos.x, 0)),
|
||||
float(max(rootPos.y, 0)),
|
||||
float(min(rootPos.x + m_WindowSize.width, m_WindowSize.width)),
|
||||
float(min(rootPos.y + m_WindowSize.height, m_WindowSize.height))
|
||||
);
|
||||
pRT->SetTransform(D2D1::Matrix3x2F::Identity());
|
||||
pRT->PushAxisAlignedClip(clipRect, D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
|
||||
pRT->PushLayer(m_sNextLayerParam, m_pNextLayer);
|
||||
|
||||
// 渲染场景
|
||||
m_pNextScene->_render();
|
||||
|
||||
pRT->PopLayer();
|
||||
pRT->PopAxisAlignedClip();
|
||||
}
|
||||
}
|
||||
|
||||
void e2d::Transition::_stop()
|
||||
{
|
||||
m_bEnd = true;
|
||||
_reset();
|
||||
return new (std::nothrow) TransitionMove(duration, direct);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,135 @@
|
|||
#include "..\e2dbase.h"
|
||||
#include "..\e2dtransition.h"
|
||||
#include "..\e2dnode.h"
|
||||
|
||||
e2d::TransitionBase::TransitionBase(double duration)
|
||||
: m_bEnd(false)
|
||||
, m_fLast(0)
|
||||
, m_fRateOfProgress(0)
|
||||
, m_pPrevScene(nullptr)
|
||||
, m_pNextScene(nullptr)
|
||||
, m_pPrevLayer(nullptr)
|
||||
, m_pNextLayer(nullptr)
|
||||
, m_sPrevLayerParam()
|
||||
, m_sNextLayerParam()
|
||||
{
|
||||
m_fDuration = max(duration, 0);
|
||||
}
|
||||
|
||||
e2d::TransitionBase::~TransitionBase()
|
||||
{
|
||||
SafeReleaseInterface(&m_pPrevLayer);
|
||||
SafeReleaseInterface(&m_pNextLayer);
|
||||
}
|
||||
|
||||
bool e2d::TransitionBase::isEnding()
|
||||
{
|
||||
return m_bEnd;
|
||||
}
|
||||
|
||||
void e2d::TransitionBase::destroy()
|
||||
{
|
||||
SafeRelease(&m_pPrevScene);
|
||||
SafeRelease(&m_pNextScene);
|
||||
}
|
||||
|
||||
void e2d::TransitionBase::_init(Scene * prev, Scene * next)
|
||||
{
|
||||
// 创建图层
|
||||
HRESULT hr = Renderer::getRenderTarget()->CreateLayer(&m_pNextLayer);
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = Renderer::getRenderTarget()->CreateLayer(&m_pPrevLayer);
|
||||
}
|
||||
|
||||
if (FAILED(hr))
|
||||
{
|
||||
ASSERT(false, "Create layer failed!");
|
||||
}
|
||||
|
||||
m_fLast = Time::getTotalTime();
|
||||
m_pPrevScene = prev;
|
||||
m_pNextScene = next;
|
||||
if (m_pPrevScene) m_pPrevScene->retain();
|
||||
if (m_pNextScene) m_pNextScene->retain();
|
||||
|
||||
m_WindowSize = Window::getSize();
|
||||
m_sPrevLayerParam = m_sNextLayerParam = D2D1::LayerParameters();
|
||||
}
|
||||
|
||||
void e2d::TransitionBase::_update()
|
||||
{
|
||||
// 计算动画进度
|
||||
if (m_fDuration == 0)
|
||||
{
|
||||
m_fRateOfProgress = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_fRateOfProgress = min((Time::getTotalTime() - m_fLast) / m_fDuration, 1);
|
||||
}
|
||||
|
||||
this->_updateCustom();
|
||||
|
||||
// 更新场景内容
|
||||
if (m_pPrevScene)
|
||||
{
|
||||
m_pPrevScene->_update();
|
||||
}
|
||||
if (m_pNextScene)
|
||||
{
|
||||
m_pNextScene->_update();
|
||||
}
|
||||
}
|
||||
|
||||
void e2d::TransitionBase::_render()
|
||||
{
|
||||
auto pRT = Renderer::getRenderTarget();
|
||||
|
||||
if (m_pPrevScene)
|
||||
{
|
||||
Point rootPos = m_pPrevScene->getRoot()->getPos();
|
||||
auto clipRect = D2D1::RectF(
|
||||
float(max(rootPos.x, 0)),
|
||||
float(max(rootPos.y, 0)),
|
||||
float(min(rootPos.x + m_WindowSize.width, m_WindowSize.width)),
|
||||
float(min(rootPos.y + m_WindowSize.height, m_WindowSize.height))
|
||||
);
|
||||
pRT->SetTransform(D2D1::Matrix3x2F::Identity());
|
||||
pRT->PushAxisAlignedClip(clipRect, D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
|
||||
pRT->PushLayer(m_sPrevLayerParam, m_pPrevLayer);
|
||||
|
||||
// 渲染场景
|
||||
m_pPrevScene->_render();
|
||||
|
||||
pRT->PopLayer();
|
||||
pRT->PopAxisAlignedClip();
|
||||
}
|
||||
|
||||
if (m_pNextScene)
|
||||
{
|
||||
Point rootPos = m_pNextScene->getRoot()->getPos();
|
||||
auto clipRect = D2D1::RectF(
|
||||
float(max(rootPos.x, 0)),
|
||||
float(max(rootPos.y, 0)),
|
||||
float(min(rootPos.x + m_WindowSize.width, m_WindowSize.width)),
|
||||
float(min(rootPos.y + m_WindowSize.height, m_WindowSize.height))
|
||||
);
|
||||
pRT->SetTransform(D2D1::Matrix3x2F::Identity());
|
||||
pRT->PushAxisAlignedClip(clipRect, D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
|
||||
pRT->PushLayer(m_sNextLayerParam, m_pNextLayer);
|
||||
|
||||
// 渲染场景
|
||||
m_pNextScene->_render();
|
||||
|
||||
pRT->PopLayer();
|
||||
pRT->PopAxisAlignedClip();
|
||||
}
|
||||
}
|
||||
|
||||
void e2d::TransitionBase::_stop()
|
||||
{
|
||||
m_bEnd = true;
|
||||
_reset();
|
||||
}
|
||||
|
|
@ -2,13 +2,13 @@
|
|||
#include "..\e2dnode.h"
|
||||
|
||||
e2d::TransitionEmerge::TransitionEmerge(double duration)
|
||||
: Transition(duration)
|
||||
: TransitionBase(duration)
|
||||
{
|
||||
}
|
||||
|
||||
void e2d::TransitionEmerge::_init(Scene * prev, Scene * next)
|
||||
{
|
||||
Transition::_init(prev, next);
|
||||
TransitionBase::_init(prev, next);
|
||||
m_sPrevLayerParam.opacity = 1;
|
||||
m_sNextLayerParam.opacity = 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
#include "..\e2dnode.h"
|
||||
|
||||
e2d::TransitionFade::TransitionFade(double duration)
|
||||
: Transition(0)
|
||||
: TransitionBase(0)
|
||||
, m_fFadeOutDuration(max(duration / 2, 0))
|
||||
, m_fFadeInDuration(max(duration / 2, 0))
|
||||
, m_bFadeOutTransioning(true)
|
||||
|
|
@ -10,7 +10,7 @@ e2d::TransitionFade::TransitionFade(double duration)
|
|||
}
|
||||
|
||||
e2d::TransitionFade::TransitionFade(double fadeOutDuration, double fadeInDuration)
|
||||
: Transition(0)
|
||||
: TransitionBase(0)
|
||||
, m_fFadeOutDuration(max(fadeOutDuration, 0))
|
||||
, m_fFadeInDuration(max(fadeInDuration, 0))
|
||||
, m_bFadeOutTransioning(true)
|
||||
|
|
@ -19,7 +19,7 @@ e2d::TransitionFade::TransitionFade(double fadeOutDuration, double fadeInDuratio
|
|||
|
||||
void e2d::TransitionFade::_init(Scene * prev, Scene * next)
|
||||
{
|
||||
Transition::_init(prev, next);
|
||||
TransitionBase::_init(prev, next);
|
||||
if (m_pPrevScene)
|
||||
{
|
||||
m_bFadeOutTransioning = true;
|
||||
|
|
|
|||
|
|
@ -2,14 +2,14 @@
|
|||
#include "..\e2dnode.h"
|
||||
|
||||
e2d::TransitionMove::TransitionMove(double duration, Direct direct)
|
||||
: Transition(duration)
|
||||
: TransitionBase(duration)
|
||||
, m_Direct(direct)
|
||||
{
|
||||
}
|
||||
|
||||
void e2d::TransitionMove::_init(Scene * prev, Scene * next)
|
||||
{
|
||||
Transition::_init(prev, next);
|
||||
TransitionBase::_init(prev, next);
|
||||
|
||||
double width = m_WindowSize.width;
|
||||
double height = m_WindowSize.height;
|
||||
|
|
|
|||
411
core/e2daction.h
411
core/e2daction.h
|
|
@ -6,25 +6,166 @@ namespace e2d
|
|||
|
||||
|
||||
class ActionManager;
|
||||
class ActionBase;
|
||||
class ActionMoveBy;
|
||||
class ActionMoveTo;
|
||||
class ActionScaleBy;
|
||||
class ActionScaleTo;
|
||||
class ActionOpacityBy;
|
||||
class ActionOpacityTo;
|
||||
class ActionFadeIn;
|
||||
class ActionFadeOut;
|
||||
class ActionRotateBy;
|
||||
class ActionRotateTo;
|
||||
class ActionTwo;
|
||||
class ActionDelay;
|
||||
class ActionLoop;
|
||||
class ActionFunc;
|
||||
class ActionSequence;
|
||||
class EActionTwoAtSameTime;
|
||||
class TransitionFade;
|
||||
class Animation;
|
||||
|
||||
class Action :
|
||||
// 动作生成器
|
||||
class Action
|
||||
{
|
||||
public:
|
||||
// 创建相对位移动画
|
||||
static e2d::ActionMoveBy* MoveBy(
|
||||
double duration, /* 动画持续时长 */
|
||||
Vector vector /* 位移向量 */
|
||||
);
|
||||
|
||||
// 创建位移动画
|
||||
static e2d::ActionMoveTo* MoveTo(
|
||||
double duration, /* 动画持续时长 */
|
||||
Point pos /* 位移至目标点的坐标 */
|
||||
);
|
||||
|
||||
// 创建相对缩放动画
|
||||
static e2d::ActionScaleBy* ScaleBy(
|
||||
double duration, /* 动画持续时长 */
|
||||
double scale /* 缩放比例变化 */
|
||||
);
|
||||
|
||||
// 创建相对缩放动画
|
||||
static e2d::ActionScaleBy* ScaleBy(
|
||||
double duration, /* 动画持续时长 */
|
||||
double scaleX, /* 横向缩放比例变化 */
|
||||
double scaleY /* 纵向缩放比例变化 */
|
||||
);
|
||||
|
||||
// 创建缩放动画
|
||||
static e2d::ActionScaleTo* ScaleTo(
|
||||
double duration, /* 动画持续时长 */
|
||||
double scale /* 缩放至目标比例 */
|
||||
);
|
||||
|
||||
// 创建缩放动画
|
||||
static e2d::ActionScaleTo* ScaleTo(
|
||||
double duration, /* 动画持续时长 */
|
||||
double scaleX, /* 横向缩放至目标比例 */
|
||||
double scaleY /* 纵向缩放至目标比例 */
|
||||
);
|
||||
|
||||
// 创建透明度相对渐变动画
|
||||
static e2d::ActionOpacityBy* OpacityBy(
|
||||
double duration, /* 动画持续时长 */
|
||||
double opacity /* 透明度相对变化值 */
|
||||
);
|
||||
|
||||
// 创建透明度渐变动画
|
||||
static e2d::ActionOpacityTo* OpacityTo(
|
||||
double duration, /* 动画持续时长 */
|
||||
double opacity /* 透明度渐变至目标值 */
|
||||
);
|
||||
|
||||
// 创建淡入动画
|
||||
static e2d::ActionFadeIn* FadeIn(
|
||||
double duration /* 动画持续时长 */
|
||||
);
|
||||
|
||||
// 创建淡出动画
|
||||
static e2d::ActionFadeOut* FadeOut(
|
||||
double duration /* 动画持续时长 */
|
||||
);
|
||||
|
||||
// 创建相对旋转动画
|
||||
static e2d::ActionRotateBy* RotateBy(
|
||||
double duration, /* 动画持续时长 */
|
||||
double rotation /* 旋转角度变化值 */
|
||||
);
|
||||
|
||||
// 创建旋转动画
|
||||
static e2d::ActionRotateTo* RotateTo(
|
||||
double duration, /* 动画持续时长 */
|
||||
double rotation /* 旋转角度至目标值 */
|
||||
);
|
||||
|
||||
// 创建两个动作的连续动作
|
||||
static e2d::ActionTwo* Two(
|
||||
ActionBase * pActionFirst, /* 第一个动作 */
|
||||
ActionBase * pActionSecond, /* 第二个动作 */
|
||||
bool bAtSameTime = false /* 同时开始 */
|
||||
);
|
||||
|
||||
// 创建延时动作
|
||||
static e2d::ActionDelay* Delay(
|
||||
double duration /* 延迟时长(秒) */
|
||||
);
|
||||
|
||||
// 创建循环动作
|
||||
static e2d::ActionLoop* Loop(
|
||||
ActionBase * action, /* 执行循环的动作 */
|
||||
int times = -1 /* 循环次数 */
|
||||
);
|
||||
|
||||
// 创建执行函数对象的动作
|
||||
static e2d::ActionFunc* Func(
|
||||
Function func /* 函数对象 */
|
||||
);
|
||||
|
||||
#ifdef HIGHER_THAN_VS2012
|
||||
// 创建顺序动作
|
||||
static e2d::ActionSequence* Sequence(
|
||||
const InitList<ActionBase*>& vActions /* 动作数组 */
|
||||
);
|
||||
|
||||
// 创建特定帧间隔的帧动画
|
||||
static e2d::Animation* Animation(
|
||||
double interval, /* 帧间隔(秒) */
|
||||
const InitList<Image*>& vFrames /* 关键帧数组 */
|
||||
);
|
||||
#else
|
||||
// 创建顺序动作
|
||||
static e2d::ActionSequence* Sequence(
|
||||
int number, /* 动作数量 */
|
||||
ActionBase * action1, /* 第一个动作 */
|
||||
...
|
||||
);
|
||||
|
||||
// 创建特定帧间隔的帧动画
|
||||
static e2d::Animation* Animation(
|
||||
double interval, /* 帧间隔(秒) */
|
||||
int number, /* 帧数量 */
|
||||
Image * frame, /* 第一帧 */
|
||||
...
|
||||
);
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
// 基础动作
|
||||
class ActionBase :
|
||||
public Object
|
||||
{
|
||||
friend ActionManager;
|
||||
friend ActionTwo;
|
||||
friend ActionLoop;
|
||||
friend ActionSequence;
|
||||
friend EActionTwoAtSameTime;
|
||||
|
||||
public:
|
||||
Action();
|
||||
ActionBase();
|
||||
|
||||
virtual ~Action();
|
||||
virtual ~ActionBase();
|
||||
|
||||
// 获取动作运行状态
|
||||
virtual bool isRunning();
|
||||
|
|
@ -52,10 +193,10 @@ public:
|
|||
);
|
||||
|
||||
// 获取一个新的逆向动作
|
||||
virtual Action * reverse() const;
|
||||
virtual ActionBase * reverse() const;
|
||||
|
||||
// 获取一个新的拷贝动作
|
||||
virtual Action * clone() const = 0;
|
||||
virtual ActionBase * clone() const = 0;
|
||||
|
||||
// 重置动作
|
||||
virtual void reset();
|
||||
|
|
@ -91,7 +232,7 @@ protected:
|
|||
|
||||
|
||||
class ActionGradual :
|
||||
public Action
|
||||
public ActionBase
|
||||
{
|
||||
public:
|
||||
// 创建特定时长的持续动画
|
||||
|
|
@ -356,13 +497,13 @@ protected:
|
|||
|
||||
|
||||
class ActionTwo :
|
||||
public Action
|
||||
public ActionBase
|
||||
{
|
||||
public:
|
||||
// 创建两个动作的连续动作
|
||||
ActionTwo(
|
||||
Action * pActionFirst, /* 第一个动作 */
|
||||
Action * pActionSecond, /* 第二个动作 */
|
||||
ActionBase * pActionFirst, /* 第一个动作 */
|
||||
ActionBase * pActionSecond, /* 第二个动作 */
|
||||
bool bAtSameTime = false /* 同时开始 */
|
||||
);
|
||||
|
||||
|
|
@ -393,14 +534,14 @@ protected:
|
|||
virtual void _resetTime() override;
|
||||
|
||||
protected:
|
||||
Action* m_pFirstAction;
|
||||
Action* m_pSecondAction;
|
||||
ActionBase* m_pFirstAction;
|
||||
ActionBase* m_pSecondAction;
|
||||
bool m_bAtSameTime;
|
||||
};
|
||||
|
||||
|
||||
class ActionSequence :
|
||||
public Action
|
||||
public ActionBase
|
||||
{
|
||||
public:
|
||||
// 创建顺序动作
|
||||
|
|
@ -409,13 +550,13 @@ public:
|
|||
#ifdef HIGHER_THAN_VS2012
|
||||
// 创建顺序动作
|
||||
ActionSequence(
|
||||
const InitList<Action*>& vActions /* 动作数组 */
|
||||
const InitList<ActionBase*>& vActions /* 动作数组 */
|
||||
);
|
||||
#else
|
||||
// 创建顺序动作
|
||||
ActionSequence(
|
||||
int number, /* 动作数量 */
|
||||
Action * action, /* 第一个动作 */
|
||||
ActionBase * action, /* 第一个动作 */
|
||||
...
|
||||
);
|
||||
#endif
|
||||
|
|
@ -424,19 +565,19 @@ public:
|
|||
|
||||
// 在结尾添加动作
|
||||
void add(
|
||||
Action * action
|
||||
ActionBase * action
|
||||
);
|
||||
|
||||
#ifdef HIGHER_THAN_VS2012
|
||||
// 在结尾添加多个动作
|
||||
void add(
|
||||
const InitList<Action*>& vActions /* 动作数组 */
|
||||
const InitList<ActionBase*>& vActions /* 动作数组 */
|
||||
);
|
||||
#else
|
||||
// 在结尾添加多个动作
|
||||
void add(
|
||||
int number, /* 动作数量 */
|
||||
Action * action, /* 第一个动作 */
|
||||
ActionBase * action, /* 第一个动作 */
|
||||
...
|
||||
);
|
||||
#endif
|
||||
|
|
@ -467,12 +608,12 @@ protected:
|
|||
|
||||
protected:
|
||||
UINT m_nActionIndex;
|
||||
std::vector<Action*> m_vActions;
|
||||
std::vector<ActionBase*> m_vActions;
|
||||
};
|
||||
|
||||
|
||||
class ActionDelay :
|
||||
public Action
|
||||
public ActionBase
|
||||
{
|
||||
public:
|
||||
// 创建延时动作
|
||||
|
|
@ -496,12 +637,12 @@ protected:
|
|||
|
||||
|
||||
class ActionLoop :
|
||||
public Action
|
||||
public ActionBase
|
||||
{
|
||||
public:
|
||||
// 创建循环动作
|
||||
ActionLoop(
|
||||
Action * action, /* 执行循环的动作 */
|
||||
ActionBase * action, /* 执行循环的动作 */
|
||||
int times = -1 /* 循环次数 */
|
||||
);
|
||||
|
||||
|
|
@ -527,14 +668,14 @@ protected:
|
|||
virtual void _resetTime() override;
|
||||
|
||||
protected:
|
||||
Action * m_pAction;
|
||||
ActionBase * m_pAction;
|
||||
int m_nTimes;
|
||||
int m_nTotalTimes;
|
||||
};
|
||||
|
||||
|
||||
class Animation :
|
||||
public Action
|
||||
public ActionBase
|
||||
{
|
||||
public:
|
||||
// 创建帧动画
|
||||
|
|
@ -626,7 +767,7 @@ protected:
|
|||
|
||||
|
||||
class ActionFunc :
|
||||
public Action
|
||||
public ActionBase
|
||||
{
|
||||
public:
|
||||
// 创建执行函数对象的动作
|
||||
|
|
@ -648,219 +789,5 @@ protected:
|
|||
Function m_Callback;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
namespace action
|
||||
{
|
||||
// 创建相对位移动画
|
||||
inline e2d::ActionMoveBy* MoveBy(
|
||||
double duration, /* 动画持续时长 */
|
||||
Vector vector /* 位移向量 */
|
||||
)
|
||||
{
|
||||
return new (std::nothrow) ActionMoveBy(duration, vector);
|
||||
}
|
||||
|
||||
// 创建位移动画
|
||||
inline e2d::ActionMoveTo* MoveTo(
|
||||
double duration, /* 动画持续时长 */
|
||||
Point pos /* 位移至目标点的坐标 */
|
||||
)
|
||||
{
|
||||
return new (std::nothrow) ActionMoveTo(duration, pos);
|
||||
}
|
||||
|
||||
// 创建相对缩放动画
|
||||
inline e2d::ActionScaleBy* ScaleBy(
|
||||
double duration, /* 动画持续时长 */
|
||||
double scale /* 缩放比例变化 */
|
||||
)
|
||||
{
|
||||
return new (std::nothrow) ActionScaleBy(duration, scale);
|
||||
}
|
||||
|
||||
// 创建相对缩放动画
|
||||
inline e2d::ActionScaleBy* ScaleBy(
|
||||
double duration, /* 动画持续时长 */
|
||||
double scaleX, /* 横向缩放比例变化 */
|
||||
double scaleY /* 纵向缩放比例变化 */
|
||||
)
|
||||
{
|
||||
return new (std::nothrow) ActionScaleBy(duration, scaleX, scaleY);
|
||||
}
|
||||
|
||||
// 创建缩放动画
|
||||
inline e2d::ActionScaleTo* ScaleTo(
|
||||
double duration, /* 动画持续时长 */
|
||||
double scale /* 缩放至目标比例 */
|
||||
)
|
||||
{
|
||||
return new (std::nothrow) ActionScaleTo(duration, scale);
|
||||
}
|
||||
|
||||
// 创建缩放动画
|
||||
inline e2d::ActionScaleTo* ScaleTo(
|
||||
double duration, /* 动画持续时长 */
|
||||
double scaleX, /* 横向缩放至目标比例 */
|
||||
double scaleY /* 纵向缩放至目标比例 */
|
||||
)
|
||||
{
|
||||
return new (std::nothrow) ActionScaleTo(duration, scaleX, scaleY);
|
||||
}
|
||||
|
||||
// 创建透明度相对渐变动画
|
||||
inline e2d::ActionOpacityBy* OpacityBy(
|
||||
double duration, /* 动画持续时长 */
|
||||
double opacity /* 透明度相对变化值 */
|
||||
)
|
||||
{
|
||||
return new (std::nothrow) ActionOpacityBy(duration, opacity);
|
||||
}
|
||||
|
||||
// 创建透明度渐变动画
|
||||
inline e2d::ActionOpacityTo* OpacityTo(
|
||||
double duration, /* 动画持续时长 */
|
||||
double opacity /* 透明度渐变至目标值 */
|
||||
)
|
||||
{
|
||||
return new (std::nothrow) ActionOpacityTo(duration, opacity);
|
||||
}
|
||||
|
||||
// 创建淡入动画
|
||||
inline e2d::ActionFadeIn* FadeIn(
|
||||
double duration /* 动画持续时长 */
|
||||
)
|
||||
{
|
||||
return new (std::nothrow) ActionFadeIn(duration);
|
||||
}
|
||||
|
||||
// 创建淡出动画
|
||||
inline e2d::ActionFadeOut* FadeOut(
|
||||
double duration /* 动画持续时长 */
|
||||
)
|
||||
{
|
||||
return new (std::nothrow) ActionFadeOut(duration);
|
||||
}
|
||||
|
||||
// 创建相对旋转动画
|
||||
inline e2d::ActionRotateBy* RotateBy(
|
||||
double duration, /* 动画持续时长 */
|
||||
double rotation /* 旋转角度变化值 */
|
||||
)
|
||||
{
|
||||
return new (std::nothrow) ActionRotateBy(duration, rotation);
|
||||
}
|
||||
|
||||
// 创建旋转动画
|
||||
inline e2d::ActionRotateTo* RotateTo(
|
||||
double duration, /* 动画持续时长 */
|
||||
double rotation /* 旋转角度至目标值 */
|
||||
)
|
||||
{
|
||||
return new (std::nothrow) ActionRotateTo(duration, rotation);
|
||||
}
|
||||
|
||||
// 创建两个动作的连续动作
|
||||
inline e2d::ActionTwo* Two(
|
||||
Action * pActionFirst, /* 第一个动作 */
|
||||
Action * pActionSecond, /* 第二个动作 */
|
||||
bool bAtSameTime = false /* 同时开始 */
|
||||
)
|
||||
{
|
||||
return new (std::nothrow) ActionTwo(pActionFirst, pActionSecond, bAtSameTime);
|
||||
}
|
||||
|
||||
// 创建延时动作
|
||||
inline e2d::ActionDelay* Delay(
|
||||
double duration /* 延迟时长(秒) */
|
||||
)
|
||||
{
|
||||
return new (std::nothrow) ActionDelay(duration);
|
||||
}
|
||||
|
||||
// 创建循环动作
|
||||
inline e2d::ActionLoop* Loop(
|
||||
Action * action, /* 执行循环的动作 */
|
||||
int times = -1 /* 循环次数 */
|
||||
)
|
||||
{
|
||||
return new (std::nothrow) ActionLoop(action, times);
|
||||
}
|
||||
|
||||
// 创建执行函数对象的动作
|
||||
inline e2d::ActionFunc* Func(
|
||||
Function func /* 函数对象 */
|
||||
)
|
||||
{
|
||||
return new (std::nothrow) ActionFunc(func);
|
||||
}
|
||||
|
||||
#ifdef HIGHER_THAN_VS2012
|
||||
// 创建顺序动作
|
||||
inline e2d::ActionSequence* Sequence(
|
||||
const InitList<Action*>& vActions /* 动作数组 */
|
||||
)
|
||||
{
|
||||
return new (std::nothrow) ActionSequence(vActions);
|
||||
}
|
||||
|
||||
// 创建特定帧间隔的帧动画
|
||||
inline e2d::Animation* Animate(
|
||||
double interval, /* 帧间隔(秒) */
|
||||
const InitList<Image*>& vFrames /* 关键帧数组 */
|
||||
)
|
||||
{
|
||||
return new (std::nothrow) Animation(interval, vFrames);
|
||||
}
|
||||
#else
|
||||
// 创建顺序动作
|
||||
inline e2d::ActionSequence* Sequence(
|
||||
int number, /* 动作数量 */
|
||||
Action * action1, /* 第一个动作 */
|
||||
...
|
||||
)
|
||||
{
|
||||
auto action = new (std::nothrow) ActionSequence();
|
||||
if (action)
|
||||
{
|
||||
Action ** ppAction = &action1;
|
||||
|
||||
while (number > 0)
|
||||
{
|
||||
WARN_IF((*ppAction) == nullptr, "ActionSequence NULL pointer exception!");
|
||||
action->add(*ppAction);
|
||||
ppAction++;
|
||||
number--;
|
||||
}
|
||||
}
|
||||
return action;
|
||||
}
|
||||
|
||||
// 创建特定帧间隔的帧动画
|
||||
inline e2d::Animation* Animate(
|
||||
double interval, /* 帧间隔(秒) */
|
||||
int number, /* 帧数量 */
|
||||
Image * frame, /* 第一帧 */
|
||||
...
|
||||
)
|
||||
{
|
||||
auto animation = new (std::nothrow) Animation(interval);
|
||||
if (animation)
|
||||
{
|
||||
Image ** ppImage = &frame;
|
||||
|
||||
while (number > 0)
|
||||
{
|
||||
WARN_IF((*ppImage) == nullptr, "Animation NULL pointer exception!");
|
||||
animation->add(*ppImage);
|
||||
ppImage++;
|
||||
number--;
|
||||
}
|
||||
}
|
||||
return animation;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -692,14 +692,14 @@ protected:
|
|||
|
||||
class Node;
|
||||
class SceneManager;
|
||||
class Transition;
|
||||
class TransitionBase;
|
||||
|
||||
// ³¡¾°
|
||||
class Scene :
|
||||
public Object
|
||||
{
|
||||
friend SceneManager;
|
||||
friend Transition;
|
||||
friend TransitionBase;
|
||||
|
||||
public:
|
||||
Scene();
|
||||
|
|
|
|||
|
|
@ -10,10 +10,10 @@ class Input;
|
|||
class Renderer;
|
||||
class Node;
|
||||
class Timer;
|
||||
class Action;
|
||||
class ActionBase;
|
||||
class Music;
|
||||
class Collider;
|
||||
class Transition;
|
||||
class TransitionBase;
|
||||
|
||||
// 对象管理器
|
||||
class ObjectManager
|
||||
|
|
@ -49,13 +49,13 @@ public:
|
|||
// 切换场景
|
||||
static void enter(
|
||||
Scene * scene, /* 下一个场景的指针 */
|
||||
Transition * transition = nullptr, /* 场景切换动画 */
|
||||
TransitionBase * transition = nullptr, /* 场景切换动画 */
|
||||
bool saveCurrentScene = true /* 是否保存当前场景 */
|
||||
);
|
||||
|
||||
// 返回上一场景
|
||||
static void back(
|
||||
Transition * transition = nullptr /* 场景切换动画 */
|
||||
TransitionBase * transition = nullptr /* 场景切换动画 */
|
||||
);
|
||||
|
||||
// 清空保存的所有场景
|
||||
|
|
@ -90,7 +90,7 @@ class ActionManager
|
|||
{
|
||||
friend Game;
|
||||
friend Node;
|
||||
friend Action;
|
||||
friend ActionBase;
|
||||
|
||||
public:
|
||||
// 继续名称相同的所有动作
|
||||
|
|
@ -118,12 +118,12 @@ public:
|
|||
static void stopAll();
|
||||
|
||||
// 获取所有名称相同的动作
|
||||
static std::vector<Action *> get(
|
||||
static std::vector<ActionBase *> get(
|
||||
String strActionName
|
||||
);
|
||||
|
||||
// 获取所有动作
|
||||
static std::vector<Action*> getAll();
|
||||
static std::vector<ActionBase*> getAll();
|
||||
|
||||
private:
|
||||
// 更新动画状态
|
||||
|
|
@ -131,17 +131,17 @@ private:
|
|||
|
||||
// 添加动作
|
||||
static void __add(
|
||||
Action * pAction
|
||||
ActionBase * pAction
|
||||
);
|
||||
|
||||
// 删除动作
|
||||
static void __remove(
|
||||
Action * pAction
|
||||
ActionBase * pAction
|
||||
);
|
||||
|
||||
// 执行动作
|
||||
static void __startAction(
|
||||
Action * pAction,
|
||||
ActionBase * pAction,
|
||||
Node * pTargetNode
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ namespace e2d
|
|||
{
|
||||
|
||||
|
||||
class Action;
|
||||
class Transition;
|
||||
class ActionBase;
|
||||
class TransitionBase;
|
||||
class Collider;
|
||||
class ColliderManager;
|
||||
|
||||
|
|
@ -15,7 +15,7 @@ class Node :
|
|||
{
|
||||
friend Scene;
|
||||
friend Collider;
|
||||
friend Transition;
|
||||
friend TransitionBase;
|
||||
friend ColliderManager;
|
||||
|
||||
public:
|
||||
|
|
@ -367,7 +367,7 @@ public:
|
|||
|
||||
// 执行动画
|
||||
virtual void runAction(
|
||||
Action * action
|
||||
ActionBase * action
|
||||
);
|
||||
|
||||
// 继续动画
|
||||
|
|
@ -386,12 +386,12 @@ public:
|
|||
);
|
||||
|
||||
// 获取名称相同的动画
|
||||
virtual Action * getAction(
|
||||
virtual ActionBase * getAction(
|
||||
String strActionName
|
||||
);
|
||||
|
||||
// 获取所有名称相同的动画
|
||||
virtual std::vector<Action*> getActions(
|
||||
virtual std::vector<ActionBase*> getActions(
|
||||
String strActionName
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -6,16 +6,49 @@ namespace e2d
|
|||
|
||||
|
||||
class SceneManager;
|
||||
class TransitionEmerge;
|
||||
class TransitionFade;
|
||||
class TransitionMove;
|
||||
|
||||
class Transition :
|
||||
|
||||
// 场景过渡动画生成器
|
||||
class Transition
|
||||
{
|
||||
public:
|
||||
// 创建淡入淡出式的场景切换动画
|
||||
static TransitionFade * Fade(
|
||||
double duration /* 动画持续时长 */
|
||||
);
|
||||
|
||||
// 创建淡入淡出式的场景切换动画
|
||||
static TransitionFade * Fade(
|
||||
double fadeOutDuration, /* 前一场景淡出动画持续时长 */
|
||||
double fadeInDuration /* 后一场景淡入动画持续时长 */
|
||||
);
|
||||
|
||||
// 创建浮现式的场景切换动画
|
||||
static TransitionEmerge * Emerge(
|
||||
double duration /* 动画持续时长 */
|
||||
);
|
||||
|
||||
// 创建移动式的场景切换动画
|
||||
static TransitionMove * Move(
|
||||
double duration, /* 动画持续时长 */
|
||||
Direct direct = Direct::LEFT /* 场景移动方向 */
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
// 基础过渡动画
|
||||
class TransitionBase :
|
||||
public Object
|
||||
{
|
||||
friend SceneManager;
|
||||
|
||||
public:
|
||||
Transition(double duration);
|
||||
TransitionBase(double duration);
|
||||
|
||||
virtual ~Transition();
|
||||
virtual ~TransitionBase();
|
||||
|
||||
// 场景切换动画是否结束
|
||||
bool isEnding();
|
||||
|
|
@ -61,7 +94,7 @@ protected:
|
|||
|
||||
|
||||
class TransitionFade :
|
||||
public Transition
|
||||
public TransitionBase
|
||||
{
|
||||
public:
|
||||
// 创建淡入淡出式的场景切换动画
|
||||
|
|
@ -94,7 +127,7 @@ protected:
|
|||
|
||||
|
||||
class TransitionEmerge :
|
||||
public Transition
|
||||
public TransitionBase
|
||||
{
|
||||
public:
|
||||
// 创建浮现式的场景切换动画
|
||||
|
|
@ -116,7 +149,7 @@ protected:
|
|||
|
||||
|
||||
class TransitionMove :
|
||||
public Transition
|
||||
public TransitionBase
|
||||
{
|
||||
public:
|
||||
// 创建移动式的场景切换动画
|
||||
|
|
|
|||
|
|
@ -197,6 +197,7 @@
|
|||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\core\Action\Action.cpp" />
|
||||
<ClCompile Include="..\..\core\Action\ActionBase.cpp" />
|
||||
<ClCompile Include="..\..\core\Action\ActionFunc.cpp" />
|
||||
<ClCompile Include="..\..\core\Action\ActionDelay.cpp" />
|
||||
<ClCompile Include="..\..\core\Action\ActionMoveBy.cpp" />
|
||||
|
|
@ -253,6 +254,7 @@
|
|||
<ClCompile Include="..\..\core\Tool\Random.cpp" />
|
||||
<ClCompile Include="..\..\core\Tool\Timer.cpp" />
|
||||
<ClCompile Include="..\..\core\Transition\Transition.cpp" />
|
||||
<ClCompile Include="..\..\core\Transition\TransitionBase.cpp" />
|
||||
<ClCompile Include="..\..\core\Transition\TransitionEmerge.cpp" />
|
||||
<ClCompile Include="..\..\core\Transition\TransitionFade.cpp" />
|
||||
<ClCompile Include="..\..\core\Transition\TransitionMove.cpp" />
|
||||
|
|
|
|||
|
|
@ -36,9 +36,6 @@
|
|||
<ClCompile Include="..\..\core\Base\Input.cpp">
|
||||
<Filter>Base</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\core\Action\Action.cpp">
|
||||
<Filter>Action</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\core\Action\ActionDelay.cpp">
|
||||
<Filter>Action</Filter>
|
||||
</ClCompile>
|
||||
|
|
@ -147,9 +144,6 @@
|
|||
<ClCompile Include="..\..\core\Common\Size.cpp">
|
||||
<Filter>Common</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\core\Transition\Transition.cpp">
|
||||
<Filter>Transition</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\core\Transition\TransitionEmerge.cpp">
|
||||
<Filter>Transition</Filter>
|
||||
</ClCompile>
|
||||
|
|
@ -213,6 +207,18 @@
|
|||
<ClCompile Include="..\..\core\Common\Function.cpp">
|
||||
<Filter>Common</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\core\Action\ActionBase.cpp">
|
||||
<Filter>Action</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\core\Action\Action.cpp">
|
||||
<Filter>Action</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\core\Transition\TransitionBase.cpp">
|
||||
<Filter>Transition</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\core\Transition\Transition.cpp">
|
||||
<Filter>Transition</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\core\easy2d.h" />
|
||||
|
|
|
|||
Loading…
Reference in New Issue