新增EActions
This commit is contained in:
parent
59e4004294
commit
b87998b6a8
|
|
@ -0,0 +1,84 @@
|
|||
#include "..\eactions.h"
|
||||
|
||||
e2d::EAction::EAction() :
|
||||
m_bRunning(true),
|
||||
m_bWaiting(false),
|
||||
m_bEnding(false),
|
||||
m_bInit(false),
|
||||
m_pTarget(nullptr),
|
||||
m_pParentScene(nullptr)
|
||||
{
|
||||
// 默认动作 15ms 运行一次
|
||||
setInterval(15);
|
||||
}
|
||||
|
||||
e2d::EAction::~EAction()
|
||||
{
|
||||
}
|
||||
|
||||
bool e2d::EAction::isRunning()
|
||||
{
|
||||
return m_bRunning && !m_bWaiting;
|
||||
}
|
||||
|
||||
bool e2d::EAction::isEnding()
|
||||
{
|
||||
return m_bEnding;
|
||||
}
|
||||
|
||||
void e2d::EAction::start()
|
||||
{
|
||||
m_bRunning = true;
|
||||
}
|
||||
|
||||
void e2d::EAction::resume()
|
||||
{
|
||||
m_bRunning = true;
|
||||
}
|
||||
|
||||
void e2d::EAction::pause()
|
||||
{
|
||||
m_bRunning = false;
|
||||
}
|
||||
|
||||
void e2d::EAction::stop()
|
||||
{
|
||||
m_bEnding = true;
|
||||
}
|
||||
void e2d::EAction::wait()
|
||||
{
|
||||
m_bWaiting = true;
|
||||
}
|
||||
|
||||
void e2d::EAction::notify()
|
||||
{
|
||||
m_bWaiting = false;
|
||||
}
|
||||
|
||||
void e2d::EAction::setInterval(LONGLONG milliSeconds)
|
||||
{
|
||||
// 设置动作的时间间隔
|
||||
m_nAnimationInterval = milliSeconds;
|
||||
}
|
||||
|
||||
e2d::EAction * e2d::EAction::reverse() const
|
||||
{
|
||||
assert(0);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
e2d::ENode * e2d::EAction::getTarget()
|
||||
{
|
||||
return m_pTarget;
|
||||
}
|
||||
|
||||
void e2d::EAction::_init()
|
||||
{
|
||||
m_bInit = true;
|
||||
}
|
||||
|
||||
void e2d::EAction::_reset()
|
||||
{
|
||||
m_bInit = false;
|
||||
m_bEnding = false;
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
#include "..\eactions.h"
|
||||
|
||||
e2d::ActionCallback::ActionCallback(const std::function<void()>& callback) :
|
||||
m_Callback(callback)
|
||||
{
|
||||
}
|
||||
|
||||
e2d::ActionCallback::~ActionCallback()
|
||||
{
|
||||
}
|
||||
|
||||
e2d::ActionCallback * e2d::ActionCallback::copy() const
|
||||
{
|
||||
return new ActionCallback(m_Callback);
|
||||
}
|
||||
|
||||
void e2d::ActionCallback::_init()
|
||||
{
|
||||
EAction::_init();
|
||||
}
|
||||
|
||||
void e2d::ActionCallback::_exec()
|
||||
{
|
||||
m_Callback();
|
||||
this->stop();
|
||||
}
|
||||
|
||||
void e2d::ActionCallback::_reset()
|
||||
{
|
||||
EAction::_reset();
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
#include "..\eactions.h"
|
||||
#include "..\Win\winbase.h"
|
||||
|
||||
e2d::ActionDelay::ActionDelay(float duration)
|
||||
{
|
||||
setInterval(LONGLONG(duration * 1000));
|
||||
}
|
||||
|
||||
e2d::ActionDelay::~ActionDelay()
|
||||
{
|
||||
}
|
||||
|
||||
e2d::ActionDelay * e2d::ActionDelay::copy() const
|
||||
{
|
||||
return new ActionDelay(m_nAnimationInterval / 1000.0f);
|
||||
}
|
||||
|
||||
void e2d::ActionDelay::_init()
|
||||
{
|
||||
EAction::_init();
|
||||
// 记录当前时间
|
||||
m_nLast = GetNow();
|
||||
}
|
||||
|
||||
void e2d::ActionDelay::_exec()
|
||||
{
|
||||
// 判断时间间隔是否足够
|
||||
if (GetInterval(m_nLast) > m_nAnimationInterval)
|
||||
{
|
||||
this->stop();
|
||||
}
|
||||
}
|
||||
|
||||
void e2d::ActionDelay::_reset()
|
||||
{
|
||||
EAction::_reset();
|
||||
// 记录当前时间
|
||||
m_nLast = GetNow();
|
||||
}
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
#include "..\eactions.h"
|
||||
#include "..\Win\winbase.h"
|
||||
|
||||
e2d::ActionFrames::ActionFrames() :
|
||||
m_nFrameIndex(0)
|
||||
{
|
||||
// 帧动画默认 .5s 刷新一次
|
||||
setInterval(500);
|
||||
}
|
||||
|
||||
e2d::ActionFrames::ActionFrames(LONGLONG frameDelay) :
|
||||
m_nFrameIndex(0)
|
||||
{
|
||||
setInterval(frameDelay);
|
||||
}
|
||||
|
||||
e2d::ActionFrames::~ActionFrames()
|
||||
{
|
||||
for (auto frame : m_vFrames)
|
||||
{
|
||||
frame->autoRelease();
|
||||
frame->release();
|
||||
}
|
||||
}
|
||||
|
||||
void e2d::ActionFrames::_init()
|
||||
{
|
||||
EAction::_init();
|
||||
// 记录当前时间
|
||||
m_nLast = GetNow();
|
||||
}
|
||||
|
||||
void e2d::ActionFrames::_exec()
|
||||
{
|
||||
// 判断时间间隔是否足够
|
||||
while (GetInterval(m_nLast) > m_nAnimationInterval)
|
||||
{
|
||||
// 重新记录时间
|
||||
m_nLast += milliseconds(m_nAnimationInterval);
|
||||
m_pTarget->setImage(m_vFrames[m_nFrameIndex]);
|
||||
m_nFrameIndex++;
|
||||
// 判断动作是否结束
|
||||
if (m_nFrameIndex == m_vFrames.size())
|
||||
{
|
||||
this->stop();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void e2d::ActionFrames::_reset()
|
||||
{
|
||||
EAction::_reset();
|
||||
m_nFrameIndex = 0;
|
||||
// 记录当前时间
|
||||
m_nLast = steady_clock::now();
|
||||
}
|
||||
|
||||
void e2d::ActionFrames::addFrame(Image * frame)
|
||||
{
|
||||
if (frame)
|
||||
{
|
||||
m_vFrames.push_back(frame);
|
||||
frame->retain();
|
||||
}
|
||||
}
|
||||
|
||||
e2d::ActionFrames * e2d::ActionFrames::copy() const
|
||||
{
|
||||
auto a = new ActionFrames(this->m_nAnimationInterval);
|
||||
for (auto f : m_vFrames)
|
||||
{
|
||||
a->addFrame(f);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
e2d::ActionFrames * e2d::ActionFrames::reverse() const
|
||||
{
|
||||
auto a = this->copy();
|
||||
a->m_vFrames.reserve(m_vFrames.size());
|
||||
return a;
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
#include "..\eactions.h"
|
||||
|
||||
|
||||
e2d::ActionMoveBy::ActionMoveBy(float duration, EVec vector) :
|
||||
Animation(duration)
|
||||
{
|
||||
m_MoveVector = vector;
|
||||
}
|
||||
|
||||
e2d::ActionMoveBy::~ActionMoveBy()
|
||||
{
|
||||
}
|
||||
|
||||
void e2d::ActionMoveBy::_init()
|
||||
{
|
||||
Animation::_init();
|
||||
m_BeginPos = m_pTarget->getPos();
|
||||
}
|
||||
|
||||
void e2d::ActionMoveBy::_exec()
|
||||
{
|
||||
while (Animation::_isDelayEnough())
|
||||
{
|
||||
// 计算移动位置
|
||||
float scale = static_cast<float>(m_nDuration) / m_nTotalDuration;
|
||||
// 移动 Sprite
|
||||
m_pTarget->setPos(
|
||||
m_BeginPos.x + m_MoveVector.x * scale,
|
||||
m_BeginPos.y + m_MoveVector.y * scale
|
||||
);
|
||||
// 判断动作是否结束
|
||||
if (_isEnd())
|
||||
{
|
||||
this->stop();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void e2d::ActionMoveBy::_reset()
|
||||
{
|
||||
Animation::_reset();
|
||||
}
|
||||
|
||||
e2d::ActionMoveBy * e2d::ActionMoveBy::copy() const
|
||||
{
|
||||
return new ActionMoveBy(m_nAnimationInterval / 1000.0f, m_MoveVector);
|
||||
}
|
||||
|
||||
e2d::ActionMoveBy * e2d::ActionMoveBy::reverse() const
|
||||
{
|
||||
return new ActionMoveBy(m_nTotalDuration / 1000.0f, EVec(-m_MoveVector.x, -m_MoveVector.y));
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
#include "..\eactions.h"
|
||||
|
||||
e2d::ActionMoveTo::ActionMoveTo(float duration, EPoint pos) :
|
||||
ActionMoveBy(duration, EVec())
|
||||
{
|
||||
m_EndPos = pos;
|
||||
}
|
||||
|
||||
e2d::ActionMoveTo::~ActionMoveTo()
|
||||
{
|
||||
}
|
||||
|
||||
e2d::ActionMoveTo * e2d::ActionMoveTo::copy() const
|
||||
{
|
||||
return new ActionMoveTo(m_nAnimationInterval / 1000.0f, m_EndPos);
|
||||
}
|
||||
|
||||
void e2d::ActionMoveTo::_init()
|
||||
{
|
||||
ActionMoveBy::_init();
|
||||
m_MoveVector = m_EndPos - m_BeginPos;
|
||||
}
|
||||
|
||||
void e2d::ActionMoveTo::_reset()
|
||||
{
|
||||
ActionMoveBy::_reset();
|
||||
}
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
#include "..\eactions.h"
|
||||
|
||||
e2d::ActionNeverStop::ActionNeverStop(EAction * action) :
|
||||
m_Action(action)
|
||||
{
|
||||
m_Action->retain();
|
||||
}
|
||||
|
||||
e2d::ActionNeverStop::~ActionNeverStop()
|
||||
{
|
||||
SafeRelease(&m_Action);
|
||||
}
|
||||
|
||||
e2d::ActionNeverStop * e2d::ActionNeverStop::copy() const
|
||||
{
|
||||
return new ActionNeverStop(m_Action->copy());
|
||||
}
|
||||
|
||||
void e2d::ActionNeverStop::_init()
|
||||
{
|
||||
EAction::_init();
|
||||
m_Action->m_pTarget = m_pTarget;
|
||||
m_Action->_init();
|
||||
}
|
||||
|
||||
void e2d::ActionNeverStop::_exec()
|
||||
{
|
||||
m_Action->_exec();
|
||||
|
||||
if (m_Action->isEnding())
|
||||
{
|
||||
m_Action->_reset();
|
||||
}
|
||||
}
|
||||
|
||||
void e2d::ActionNeverStop::_reset()
|
||||
{
|
||||
EAction::_reset();
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
#include "..\eactions.h"
|
||||
|
||||
|
||||
e2d::ActionOpacityBy::ActionOpacityBy(float duration, float opacity) :
|
||||
Animation(duration)
|
||||
{
|
||||
m_nVariation = opacity;
|
||||
}
|
||||
|
||||
e2d::ActionOpacityBy::~ActionOpacityBy()
|
||||
{
|
||||
}
|
||||
|
||||
void e2d::ActionOpacityBy::_init()
|
||||
{
|
||||
Animation::_init();
|
||||
m_nBeginVal = m_pTarget->getOpacity();
|
||||
}
|
||||
|
||||
void e2d::ActionOpacityBy::_exec()
|
||||
{
|
||||
while (Animation::_isDelayEnough())
|
||||
{
|
||||
// 计算移动位置
|
||||
float scale = static_cast<float>(m_nDuration) / m_nTotalDuration;
|
||||
// 移动 Sprite
|
||||
m_pTarget->setOpacity(m_nBeginVal + m_nVariation * scale);
|
||||
// 判断动作是否结束
|
||||
if (_isEnd())
|
||||
{
|
||||
this->stop();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void e2d::ActionOpacityBy::_reset()
|
||||
{
|
||||
Animation::_reset();
|
||||
}
|
||||
|
||||
e2d::ActionOpacityBy * e2d::ActionOpacityBy::copy() const
|
||||
{
|
||||
return new ActionOpacityBy(m_nAnimationInterval / 1000.0f, m_nVariation);
|
||||
}
|
||||
|
||||
e2d::ActionOpacityBy * e2d::ActionOpacityBy::reverse() const
|
||||
{
|
||||
return new ActionOpacityBy(m_nTotalDuration / 1000.0f, -m_nVariation);
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
#include "..\eactions.h"
|
||||
|
||||
|
||||
e2d::ActionOpacityTo::ActionOpacityTo(float duration, float opacity) :
|
||||
ActionOpacityBy(duration, 0)
|
||||
{
|
||||
m_nEndVal = opacity;
|
||||
}
|
||||
|
||||
e2d::ActionOpacityTo::~ActionOpacityTo()
|
||||
{
|
||||
}
|
||||
|
||||
e2d::ActionOpacityTo * e2d::ActionOpacityTo::copy() const
|
||||
{
|
||||
return new ActionOpacityTo(m_nAnimationInterval / 1000.0f, m_nEndVal);
|
||||
}
|
||||
|
||||
void e2d::ActionOpacityTo::_init()
|
||||
{
|
||||
ActionOpacityBy::_init();
|
||||
m_nVariation = m_nEndVal - m_nBeginVal;
|
||||
}
|
||||
|
||||
void e2d::ActionOpacityTo::_reset()
|
||||
{
|
||||
ActionOpacityBy::_reset();
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
#include "..\eactions.h"
|
||||
|
||||
|
||||
e2d::ActionScaleBy::ActionScaleBy(float duration, float scaleX, float scaleY) :
|
||||
Animation(duration)
|
||||
{
|
||||
m_nVariationX = scaleX;
|
||||
m_nVariationY = scaleY;
|
||||
}
|
||||
|
||||
e2d::ActionScaleBy::~ActionScaleBy()
|
||||
{
|
||||
}
|
||||
|
||||
void e2d::ActionScaleBy::_init()
|
||||
{
|
||||
Animation::_init();
|
||||
m_nBeginScaleX = m_pTarget->getScaleX();
|
||||
m_nBeginScaleY = m_pTarget->getScaleY();
|
||||
}
|
||||
|
||||
void e2d::ActionScaleBy::_exec()
|
||||
{
|
||||
while (Animation::_isDelayEnough())
|
||||
{
|
||||
// 计算移动位置
|
||||
float scale = static_cast<float>(m_nDuration) / m_nTotalDuration;
|
||||
// 移动 Sprite
|
||||
m_pTarget->setScale(m_nBeginScaleX + m_nVariationX * scale, m_nBeginScaleX + m_nVariationX * scale);
|
||||
// 判断动作是否结束
|
||||
if (_isEnd())
|
||||
{
|
||||
this->stop();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void e2d::ActionScaleBy::_reset()
|
||||
{
|
||||
Animation::_reset();
|
||||
}
|
||||
|
||||
e2d::ActionScaleBy * e2d::ActionScaleBy::copy() const
|
||||
{
|
||||
return new ActionScaleBy(m_nAnimationInterval / 1000.0f, m_nVariationX, m_nVariationY);
|
||||
}
|
||||
|
||||
e2d::ActionScaleBy * e2d::ActionScaleBy::reverse() const
|
||||
{
|
||||
return new ActionScaleBy(m_nTotalDuration / 1000.0f, -m_nVariationX, -m_nVariationY);
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
#include "..\eactions.h"
|
||||
|
||||
e2d::ActionScaleTo::ActionScaleTo(float duration, float scaleX, float scaleY) :
|
||||
ActionScaleBy(duration, 0, 0)
|
||||
{
|
||||
m_nEndScaleX = scaleX;
|
||||
m_nEndScaleY = scaleY;
|
||||
}
|
||||
|
||||
e2d::ActionScaleTo::~ActionScaleTo()
|
||||
{
|
||||
}
|
||||
|
||||
e2d::ActionScaleTo * e2d::ActionScaleTo::copy() const
|
||||
{
|
||||
return new ActionScaleTo(m_nAnimationInterval / 1000.0f, m_nEndScaleX, m_nEndScaleY);
|
||||
}
|
||||
|
||||
void e2d::ActionScaleTo::_init()
|
||||
{
|
||||
ActionScaleBy::_init();
|
||||
m_nVariationX = m_nEndScaleX - m_nBeginScaleX;
|
||||
m_nVariationY = m_nEndScaleY - m_nBeginScaleY;
|
||||
}
|
||||
|
||||
void e2d::ActionScaleTo::_reset()
|
||||
{
|
||||
ActionScaleBy::_reset();
|
||||
}
|
||||
|
|
@ -0,0 +1,105 @@
|
|||
#include "..\eactions.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
e2d::ActionSequence::ActionSequence() :
|
||||
m_nActionIndex(0)
|
||||
{
|
||||
}
|
||||
|
||||
e2d::ActionSequence::ActionSequence(int number, EAction * action1, ...) :
|
||||
m_nActionIndex(0)
|
||||
{
|
||||
va_list params;
|
||||
va_start(params, number);
|
||||
|
||||
while (number > 0)
|
||||
{
|
||||
this->addAction(va_arg(params, EAction*));
|
||||
number--;
|
||||
}
|
||||
|
||||
va_end(params);
|
||||
}
|
||||
|
||||
e2d::ActionSequence::~ActionSequence()
|
||||
{
|
||||
for (auto action : m_vActions)
|
||||
{
|
||||
SafeRelease(&action);
|
||||
}
|
||||
}
|
||||
|
||||
void e2d::ActionSequence::_init()
|
||||
{
|
||||
EAction::_init();
|
||||
// 将所有动作与目标绑定
|
||||
for (auto action : m_vActions)
|
||||
{
|
||||
action->m_pTarget = m_pTarget;
|
||||
}
|
||||
// 初始化第一个动作
|
||||
m_vActions[0]->_init();
|
||||
}
|
||||
|
||||
void e2d::ActionSequence::_exec()
|
||||
{
|
||||
m_vActions[m_nActionIndex]->_exec();
|
||||
|
||||
if (m_vActions[m_nActionIndex]->isEnding())
|
||||
{
|
||||
m_nActionIndex++;
|
||||
if (m_nActionIndex == m_vActions.size())
|
||||
{
|
||||
this->stop();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_vActions[m_nActionIndex]->_init();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void e2d::ActionSequence::_reset()
|
||||
{
|
||||
EAction::_reset();
|
||||
for (auto action : m_vActions)
|
||||
{
|
||||
action->_reset();
|
||||
}
|
||||
m_nActionIndex = 0;
|
||||
}
|
||||
|
||||
void e2d::ActionSequence::addAction(EAction * action)
|
||||
{
|
||||
m_vActions.push_back(action);
|
||||
action->retain();
|
||||
}
|
||||
|
||||
e2d::ActionSequence * e2d::ActionSequence::copy() const
|
||||
{
|
||||
auto a = new ActionSequence();
|
||||
for (auto action : m_vActions)
|
||||
{
|
||||
a->addAction(action->copy());
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
e2d::ActionSequence * e2d::ActionSequence::reverse(bool actionReverse) const
|
||||
{
|
||||
auto a = new ActionSequence();
|
||||
for (auto action : a->m_vActions)
|
||||
{
|
||||
if (actionReverse)
|
||||
{
|
||||
a->addAction(action->reverse());
|
||||
}
|
||||
else
|
||||
{
|
||||
a->addAction(action->copy());
|
||||
}
|
||||
}
|
||||
// 将动作顺序逆序排列
|
||||
a->m_vActions.reserve(m_vActions.size());
|
||||
return a;
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
#include "..\eactions.h"
|
||||
|
||||
e2d::ActionTwo::ActionTwo(EAction * actionFirst, EAction * actionSecond) :
|
||||
m_FirstAction(actionFirst),
|
||||
m_SecondAction(actionSecond)
|
||||
{
|
||||
m_FirstAction->retain();
|
||||
m_SecondAction->retain();
|
||||
}
|
||||
|
||||
e2d::ActionTwo::~ActionTwo()
|
||||
{
|
||||
SafeRelease(&m_FirstAction);
|
||||
SafeRelease(&m_SecondAction);
|
||||
}
|
||||
|
||||
e2d::ActionTwo * e2d::ActionTwo::copy() const
|
||||
{
|
||||
return new ActionTwo(m_FirstAction->copy(), m_SecondAction->copy());
|
||||
}
|
||||
|
||||
e2d::ActionTwo * e2d::ActionTwo::reverse(bool actionReverse) const
|
||||
{
|
||||
if (actionReverse)
|
||||
{
|
||||
return new ActionTwo(m_SecondAction->reverse(), m_FirstAction->reverse());
|
||||
}
|
||||
else
|
||||
{
|
||||
return new ActionTwo(m_SecondAction->copy(), m_FirstAction->copy());
|
||||
}
|
||||
}
|
||||
|
||||
void e2d::ActionTwo::_init()
|
||||
{
|
||||
EAction::_init();
|
||||
m_FirstAction->m_pTarget = m_pTarget;
|
||||
m_SecondAction->m_pTarget = m_pTarget;
|
||||
|
||||
m_FirstAction->_init();
|
||||
}
|
||||
|
||||
void e2d::ActionTwo::_exec()
|
||||
{
|
||||
if (!m_FirstAction->isEnding())
|
||||
{
|
||||
m_FirstAction->_exec();
|
||||
if (m_FirstAction->isEnding())
|
||||
{
|
||||
// 返回 true 表示第一个动作已经结束
|
||||
m_SecondAction->_init();
|
||||
}
|
||||
}
|
||||
else if (!m_SecondAction->isEnding())
|
||||
{
|
||||
m_SecondAction->_exec();
|
||||
}
|
||||
else
|
||||
{
|
||||
this->stop();
|
||||
}
|
||||
}
|
||||
|
||||
void e2d::ActionTwo::_reset()
|
||||
{
|
||||
EAction::_reset();
|
||||
|
||||
m_FirstAction->_reset();
|
||||
m_SecondAction->_reset();
|
||||
}
|
||||
|
|
@ -0,0 +1,45 @@
|
|||
#include "..\eactions.h"
|
||||
#include "..\Win\winbase.h"
|
||||
|
||||
e2d::Animation::Animation(float duration)
|
||||
{
|
||||
m_nDuration = 0;
|
||||
m_nTotalDuration = UINT(duration * 1000);
|
||||
}
|
||||
|
||||
e2d::Animation::~Animation()
|
||||
{
|
||||
}
|
||||
|
||||
bool e2d::Animation::_isEnd() const
|
||||
{
|
||||
return m_nDuration >= m_nTotalDuration;
|
||||
}
|
||||
|
||||
void e2d::Animation::_init()
|
||||
{
|
||||
EAction::_init();
|
||||
// 记录当前时间
|
||||
m_nLast = GetNow();
|
||||
}
|
||||
|
||||
bool e2d::Animation::_isDelayEnough()
|
||||
{
|
||||
// 判断时间间隔是否足够
|
||||
if (GetInterval(m_nLast) > m_nAnimationInterval)
|
||||
{
|
||||
// 重新记录时间
|
||||
m_nLast += milliseconds(m_nAnimationInterval);
|
||||
m_nDuration += m_nAnimationInterval;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void e2d::Animation::_reset()
|
||||
{
|
||||
EAction::_reset();
|
||||
m_nDuration = 0;
|
||||
// 记录当前时间
|
||||
m_nLast = GetNow();
|
||||
}
|
||||
|
|
@ -37,7 +37,10 @@ e2d::EApp::~EApp()
|
|||
// ÊÍ·Å×ÊÔ´
|
||||
SafeReleaseInterface(&GetRenderTarget());
|
||||
SafeReleaseInterface(&GetFactory());
|
||||
|
||||
SafeReleaseInterface(&GetImagingFactory());
|
||||
SafeReleaseInterface(&GetDirectWriteFactory());
|
||||
SafeReleaseInterface(&GetSolidColorBrush());
|
||||
|
||||
CoUninitialize();
|
||||
}
|
||||
|
||||
|
|
@ -297,9 +300,9 @@ void e2d::EApp::_onControl()
|
|||
// ¶ÏÑÔµ±Ç°³¡¾°·Ç¿Õ
|
||||
ASSERT(m_pCurrentScene != nullptr, "Current scene NULL pointer exception.");
|
||||
|
||||
ETimerManager::TimerProc(); // 定时器执行程序
|
||||
//ActionManager::__exec(); // 动作管理器执行程序
|
||||
EObjectManager::__flush(); // 刷新内存池
|
||||
ETimerManager::TimerProc(); // 定时器管理器执行程序
|
||||
EActionManager::ActionProc(); // 动作管理器执行程序
|
||||
EObjectManager::__flush(); // 刷新内存池
|
||||
}
|
||||
|
||||
// This method discards device-specific
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ void e2d::EScene::_onEnter()
|
|||
ETimerManager::_notifyAllTimersBindedWith(this);
|
||||
EMsgManager::_notifyAllMouseListenersBindedWith(this);
|
||||
EMsgManager::_notifyAllKeyboardListenersBindedWith(this);
|
||||
//ActionManager::notifyAllSceneActions(m_pNextScene);
|
||||
EActionManager::_notifyAllActionsBindedWith(this);
|
||||
}
|
||||
|
||||
void e2d::EScene::_onExit()
|
||||
|
|
@ -61,14 +61,14 @@ void e2d::EScene::_onExit()
|
|||
ETimerManager::_waitAllTimersBindedWith(this);
|
||||
EMsgManager::_waitAllMouseListenersBindedWith(this);
|
||||
EMsgManager::_waitAllKeyboardListenersBindedWith(this);
|
||||
//ActionManager::waitAllSceneActions(m_pCurrentScene);
|
||||
EActionManager::_waitAllActionsBindedWith(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
ETimerManager::clearAllTimersBindedWith(this);
|
||||
EMsgManager::clearAllMouseListenersBindedWith(this);
|
||||
EMsgManager::clearAllKeyboardListenersBindedWith(this);
|
||||
//ActionManager::stopAllSceneActions(m_pCurrentScene);
|
||||
EActionManager::clearAllActionsBindedWith(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
#include "etools.h"
|
||||
#include "Win\winbase.h"
|
||||
|
||||
e2d::ETimer::ETimer()
|
||||
: m_bRunning(false)
|
||||
|
|
@ -43,7 +44,7 @@ bool e2d::ETimer::isWaiting() const
|
|||
void e2d::ETimer::start()
|
||||
{
|
||||
m_bRunning = true;
|
||||
m_tLast = std::chrono::steady_clock::now();
|
||||
m_tLast = GetNow();
|
||||
}
|
||||
|
||||
void e2d::ETimer::stop()
|
||||
|
|
@ -59,7 +60,7 @@ void e2d::ETimer::_wait()
|
|||
void e2d::ETimer::_notify()
|
||||
{
|
||||
m_bWaiting = false;
|
||||
m_tLast = std::chrono::steady_clock::now();
|
||||
m_tLast = GetNow();
|
||||
}
|
||||
|
||||
e2d::EString e2d::ETimer::getName() const
|
||||
|
|
@ -97,7 +98,7 @@ void e2d::ETimer::bindWith(ENode * pParentNode)
|
|||
ETimerManager::bindTimer(this, pParentNode);
|
||||
}
|
||||
|
||||
void e2d::ETimer::_runCallback()
|
||||
void e2d::ETimer::_callOn()
|
||||
{
|
||||
m_Callback(m_nRunTimes);
|
||||
m_nRunTimes++;
|
||||
|
|
|
|||
|
|
@ -192,6 +192,20 @@
|
|||
</Lib>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Action\Action.cpp" />
|
||||
<ClCompile Include="Action\ActionCallback.cpp" />
|
||||
<ClCompile Include="Action\ActionDelay.cpp" />
|
||||
<ClCompile Include="Action\ActionFrames.cpp" />
|
||||
<ClCompile Include="Action\ActionMoveBy.cpp" />
|
||||
<ClCompile Include="Action\ActionMoveTo.cpp" />
|
||||
<ClCompile Include="Action\ActionNeverStop.cpp" />
|
||||
<ClCompile Include="Action\ActionOpacityBy.cpp" />
|
||||
<ClCompile Include="Action\ActionOpacityTo.cpp" />
|
||||
<ClCompile Include="Action\ActionScaleBy.cpp" />
|
||||
<ClCompile Include="Action\ActionScaleTo.cpp" />
|
||||
<ClCompile Include="Action\ActionSequence.cpp" />
|
||||
<ClCompile Include="Action\ActionTwo.cpp" />
|
||||
<ClCompile Include="Action\Animation.cpp" />
|
||||
<ClCompile Include="Base\EApp.cpp" />
|
||||
<ClCompile Include="Base\EObject.cpp" />
|
||||
<ClCompile Include="Base\EScene.cpp" />
|
||||
|
|
@ -210,11 +224,13 @@
|
|||
<ClCompile Include="Node\EText.cpp" />
|
||||
<ClCompile Include="Node\EFont.cpp" />
|
||||
<ClCompile Include="Node\ETexture.cpp" />
|
||||
<ClCompile Include="Tool\EActionManager.cpp" />
|
||||
<ClCompile Include="Tool\EObjectManager.cpp" />
|
||||
<ClCompile Include="Tool\ETimerManager.cpp" />
|
||||
<ClCompile Include="Win\winbase.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="eactions.h" />
|
||||
<ClInclude Include="easy2d.h" />
|
||||
<ClInclude Include="ebase.h" />
|
||||
<ClInclude Include="ecommon.h" />
|
||||
|
|
|
|||
|
|
@ -19,6 +19,9 @@
|
|||
<Filter Include="Msg\Listener">
|
||||
<UniqueIdentifier>{b9bb1728-5106-4574-998e-8564b49cb4a1}</UniqueIdentifier>
|
||||
</Filter>
|
||||
<Filter Include="Action">
|
||||
<UniqueIdentifier>{50293f38-87fe-4dde-b938-cf1b7a2921f8}</UniqueIdentifier>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="Win\winbase.cpp">
|
||||
|
|
@ -84,6 +87,51 @@
|
|||
<ClCompile Include="Node\ETexture.cpp">
|
||||
<Filter>Node</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Action\Action.cpp">
|
||||
<Filter>Action</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Action\ActionCallback.cpp">
|
||||
<Filter>Action</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Action\ActionDelay.cpp">
|
||||
<Filter>Action</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Action\ActionFrames.cpp">
|
||||
<Filter>Action</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Action\ActionMoveBy.cpp">
|
||||
<Filter>Action</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Action\ActionMoveTo.cpp">
|
||||
<Filter>Action</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Action\ActionNeverStop.cpp">
|
||||
<Filter>Action</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Action\ActionOpacityBy.cpp">
|
||||
<Filter>Action</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Action\ActionOpacityTo.cpp">
|
||||
<Filter>Action</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Action\ActionScaleBy.cpp">
|
||||
<Filter>Action</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Action\ActionScaleTo.cpp">
|
||||
<Filter>Action</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Action\ActionSequence.cpp">
|
||||
<Filter>Action</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Action\ActionTwo.cpp">
|
||||
<Filter>Action</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Action\Animation.cpp">
|
||||
<Filter>Action</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="Tool\EActionManager.cpp">
|
||||
<Filter>Tool</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="Win\winbase.h">
|
||||
|
|
@ -96,5 +144,6 @@
|
|||
<ClInclude Include="ebase.h" />
|
||||
<ClInclude Include="easy2d.h" />
|
||||
<ClInclude Include="emsg.h" />
|
||||
<ClInclude Include="eactions.h" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
|
@ -129,7 +129,7 @@ void e2d::EMsgManager::MouseProc(UINT message, WPARAM wParam, LPARAM lParam)
|
|||
{
|
||||
if (mlistener->isRunning())
|
||||
{
|
||||
mlistener->_runCallback();
|
||||
mlistener->_callOn();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -145,7 +145,7 @@ void e2d::EMsgManager::KeyboardProc(UINT message, WPARAM wParam, LPARAM lParam)
|
|||
{
|
||||
if (klistener->isRunning())
|
||||
{
|
||||
klistener->_runCallback();
|
||||
klistener->_callOn();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ e2d::EKeyboardListener::EKeyboardListener(const EString & name, const KEY_LISTEN
|
|||
m_Callback = callback;
|
||||
}
|
||||
|
||||
void e2d::EKeyboardListener::_runCallback()
|
||||
void e2d::EKeyboardListener::_callOn()
|
||||
{
|
||||
m_Callback();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ e2d::EKeyboardPressListener::EKeyboardPressListener(const EString & name, const
|
|||
{
|
||||
}
|
||||
|
||||
void e2d::EKeyboardPressListener::_runCallback()
|
||||
void e2d::EKeyboardPressListener::_callOn()
|
||||
{
|
||||
if (EKeyboardMsg::getMsg() == EKeyboardMsg::KEYBOARD_MSG::KEY_DOWN)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ e2d::EMouseClickListener::EMouseClickListener(const EString & name, const MOUSE_
|
|||
{
|
||||
}
|
||||
|
||||
void e2d::EMouseClickListener::_runCallback()
|
||||
void e2d::EMouseClickListener::_callOn()
|
||||
{
|
||||
if (EMouseMsg::getMsg() == EMouseMsg::LBUTTON_DOWN ||
|
||||
EMouseMsg::getMsg() == EMouseMsg::LBUTTON_DBLCLK)
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ e2d::EMouseDoubleClickListener::EMouseDoubleClickListener(const EString & name,
|
|||
{
|
||||
}
|
||||
|
||||
void e2d::EMouseDoubleClickListener::_runCallback()
|
||||
void e2d::EMouseDoubleClickListener::_callOn()
|
||||
{
|
||||
if (EMouseMsg::getMsg() == EMouseMsg::LBUTTON_DOWN)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ e2d::EMouseDragListener::EMouseDragListener(const EString & name, const MOUSE_DR
|
|||
{
|
||||
}
|
||||
|
||||
void e2d::EMouseDragListener::_runCallback()
|
||||
void e2d::EMouseDragListener::_callOn()
|
||||
{
|
||||
if (EMouseMsg::getMsg() == EMouseMsg::LBUTTON_DOWN ||
|
||||
EMouseMsg::getMsg() == EMouseMsg::LBUTTON_DBLCLK)
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ e2d::EMouseListener::EMouseListener(const EString & name, const MOUSE_LISTENER_C
|
|||
m_Callback = callback;
|
||||
}
|
||||
|
||||
void e2d::EMouseListener::_runCallback()
|
||||
void e2d::EMouseListener::_callOn()
|
||||
{
|
||||
m_Callback();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ e2d::EMousePressListener::EMousePressListener(const EString & name, const MOUSE_
|
|||
{
|
||||
}
|
||||
|
||||
void e2d::EMousePressListener::_runCallback()
|
||||
void e2d::EMousePressListener::_callOn()
|
||||
{
|
||||
if (EMouseMsg::getMsg() == EMouseMsg::LBUTTON_DOWN ||
|
||||
EMouseMsg::getMsg() == EMouseMsg::LBUTTON_DBLCLK)
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include "..\enodes.h"
|
||||
#include "..\emsg.h"
|
||||
#include "..\etools.h"
|
||||
#include "..\eactions.h"
|
||||
#include "..\Win\winbase.h"
|
||||
#include <algorithm>
|
||||
|
||||
|
|
@ -34,6 +35,10 @@ e2d::ENode::ENode(const EString & name)
|
|||
|
||||
e2d::ENode::~ENode()
|
||||
{
|
||||
ETimerManager::clearAllTimersBindedWith(this);
|
||||
EMsgManager::clearAllMouseListenersBindedWith(this);
|
||||
EMsgManager::clearAllKeyboardListenersBindedWith(this);
|
||||
EActionManager::clearAllActionsBindedWith(this);
|
||||
}
|
||||
|
||||
void e2d::ENode::onEnter()
|
||||
|
|
@ -105,6 +110,7 @@ void e2d::ENode::_onEnter()
|
|||
ETimerManager::_notifyAllTimersBindedWith(this);
|
||||
EMsgManager::_notifyAllMouseListenersBindedWith(this);
|
||||
EMsgManager::_notifyAllKeyboardListenersBindedWith(this);
|
||||
EActionManager::_notifyAllActionsBindedWith(this);
|
||||
this->onEnter();
|
||||
|
||||
for (const auto &child : m_vChildren)
|
||||
|
|
@ -123,6 +129,7 @@ void e2d::ENode::_onExit()
|
|||
ETimerManager::_waitAllTimersBindedWith(this);
|
||||
EMsgManager::_waitAllMouseListenersBindedWith(this);
|
||||
EMsgManager::_waitAllKeyboardListenersBindedWith(this);
|
||||
EActionManager::_waitAllActionsBindedWith(this);
|
||||
this->onExit();
|
||||
|
||||
for (const auto &child : m_vChildren)
|
||||
|
|
@ -132,17 +139,6 @@ void e2d::ENode::_onExit()
|
|||
}
|
||||
}
|
||||
|
||||
void e2d::ENode::_onClear()
|
||||
{
|
||||
ETimerManager::clearAllTimersBindedWith(this);
|
||||
EMsgManager::clearAllMouseListenersBindedWith(this);
|
||||
EMsgManager::clearAllKeyboardListenersBindedWith(this);
|
||||
for (const auto &child : m_vChildren)
|
||||
{
|
||||
child->_onClear();
|
||||
}
|
||||
}
|
||||
|
||||
void e2d::ENode::_sortChildren()
|
||||
{
|
||||
if (m_bSortChildrenNeeded)
|
||||
|
|
@ -558,7 +554,7 @@ void e2d::ENode::removeFromParent(bool release /* = false */)
|
|||
}
|
||||
}
|
||||
|
||||
bool e2d::ENode::removeChild(ENode * child, bool release /* = false */)
|
||||
bool e2d::ENode::removeChild(ENode * child, bool release /* = true */)
|
||||
{
|
||||
WARN_IF(child == nullptr, "ENode::removeChild NULL pointer exception.");
|
||||
|
||||
|
|
@ -591,7 +587,7 @@ bool e2d::ENode::removeChild(ENode * child, bool release /* = false */)
|
|||
return false;
|
||||
}
|
||||
|
||||
void e2d::ENode::removeChild(const EString & childName, bool release /* = false */)
|
||||
void e2d::ENode::removeChild(const EString & childName, bool release /* = true */)
|
||||
{
|
||||
WARN_IF(childName.empty(), "Invalid ENode name.");
|
||||
|
||||
|
|
@ -625,26 +621,31 @@ void e2d::ENode::removeChild(const EString & childName, bool release /* = false
|
|||
}
|
||||
}
|
||||
|
||||
void e2d::ENode::clearAllChildren(bool release /* = false */)
|
||||
void e2d::ENode::clearAllChildren(bool release /* = true */)
|
||||
{
|
||||
// 所有节点的引用计数减一
|
||||
for (auto child : m_vChildren)
|
||||
{
|
||||
if (release)
|
||||
{
|
||||
child->_onClear();
|
||||
child->autoRelease();
|
||||
}
|
||||
else
|
||||
{
|
||||
child->_onExit();
|
||||
}
|
||||
child->_onExit();
|
||||
child->release();
|
||||
}
|
||||
// 清空储存节点的容器
|
||||
m_vChildren.clear();
|
||||
}
|
||||
|
||||
void e2d::ENode::runAction(EAction * action)
|
||||
{
|
||||
EActionManager::bindAction(action, this);
|
||||
}
|
||||
|
||||
void e2d::ENode::stopAction(EAction * action)
|
||||
{
|
||||
}
|
||||
|
||||
void e2d::ENode::setVisiable(bool value)
|
||||
{
|
||||
m_bVisiable = value;
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
#include "..\enodes.h"
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
#include "..\etools.h"
|
||||
|
||||
|
||||
void e2d::EActionManager::bindAction(EAction * action, ENode * pParentNode)
|
||||
{
|
||||
}
|
||||
|
||||
void e2d::EActionManager::startAllActionsBindedWith(EScene * pParentScene)
|
||||
{
|
||||
}
|
||||
|
||||
void e2d::EActionManager::stopAllActionsBindedWith(EScene * pParentScene)
|
||||
{
|
||||
}
|
||||
|
||||
void e2d::EActionManager::clearAllActionsBindedWith(EScene * pParentScene)
|
||||
{
|
||||
}
|
||||
|
||||
void e2d::EActionManager::startAllActionsBindedWith(ENode * pParentNode)
|
||||
{
|
||||
}
|
||||
|
||||
void e2d::EActionManager::stopAllActionsBindedWith(ENode * pParentNode)
|
||||
{
|
||||
}
|
||||
|
||||
void e2d::EActionManager::clearAllActionsBindedWith(ENode * pParentNode)
|
||||
{
|
||||
}
|
||||
|
||||
void e2d::EActionManager::startAllActions()
|
||||
{
|
||||
}
|
||||
|
||||
void e2d::EActionManager::stopAllActions()
|
||||
{
|
||||
}
|
||||
|
||||
void e2d::EActionManager::clearAllActions()
|
||||
{
|
||||
}
|
||||
|
||||
void e2d::EActionManager::_waitAllActionsBindedWith(EScene * pParentScene)
|
||||
{
|
||||
}
|
||||
|
||||
void e2d::EActionManager::_notifyAllActionsBindedWith(EScene * pParentScene)
|
||||
{
|
||||
}
|
||||
|
||||
void e2d::EActionManager::_waitAllActionsBindedWith(ENode * pParentNode)
|
||||
{
|
||||
}
|
||||
|
||||
void e2d::EActionManager::_notifyAllActionsBindedWith(ENode * pParentNode)
|
||||
{
|
||||
}
|
||||
|
||||
void e2d::EActionManager::ActionProc()
|
||||
{
|
||||
}
|
||||
|
|
@ -257,7 +257,7 @@ void e2d::ETimerManager::TimerProc()
|
|||
{
|
||||
if (GetInterval(t->m_tLast) >= t->m_nInterval)
|
||||
{
|
||||
t->_runCallback();
|
||||
t->_callOn();
|
||||
t->m_tLast = GetNow();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
#include "winbase.h"
|
||||
using namespace std::chrono;
|
||||
|
||||
|
||||
static HWND s_HWnd = nullptr;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
#include "..\emacros.h"
|
||||
#include <chrono>
|
||||
using namespace std::chrono;
|
||||
|
||||
|
||||
#ifndef HINST_THISCOMPONENT
|
||||
|
|
|
|||
|
|
@ -0,0 +1,350 @@
|
|||
#pragma once
|
||||
#include "enodes.h"
|
||||
#include "etools.h"
|
||||
|
||||
namespace e2d
|
||||
{
|
||||
|
||||
class ActionTwo;
|
||||
class ActionNeverStop;
|
||||
class ActionSequence;
|
||||
|
||||
class EAction :
|
||||
public EObject
|
||||
{
|
||||
friend ENode;
|
||||
friend EActionManager;
|
||||
friend ActionTwo;
|
||||
friend ActionNeverStop;
|
||||
friend ActionSequence;
|
||||
|
||||
public:
|
||||
EAction();
|
||||
|
||||
virtual ~EAction();
|
||||
|
||||
// 获取动作运行状态
|
||||
virtual bool isRunning();
|
||||
// 获取动作结束状态
|
||||
virtual bool isEnding();
|
||||
// 继续动作
|
||||
virtual void start();
|
||||
// 继续动作
|
||||
virtual void resume();
|
||||
// 暂停动作
|
||||
virtual void pause();
|
||||
// 停止动作
|
||||
virtual void stop();
|
||||
// 设置动作每一帧时间间隔
|
||||
virtual void setInterval(LONGLONG milliSeconds);
|
||||
// 获取一个新的拷贝动作
|
||||
virtual EAction * copy() const = 0;
|
||||
// 获取一个新的逆向动作
|
||||
virtual EAction * reverse() const;
|
||||
// 获取执行该动作的目标
|
||||
virtual ENode * getTarget();
|
||||
|
||||
protected:
|
||||
// 初始化动作
|
||||
virtual void _init();
|
||||
|
||||
// 执行动作
|
||||
virtual void _exec() = 0;
|
||||
|
||||
// 重置动作
|
||||
virtual void _reset();
|
||||
|
||||
// 进入等待状态
|
||||
virtual void wait();
|
||||
|
||||
// 唤醒
|
||||
virtual void notify();
|
||||
|
||||
protected:
|
||||
bool m_bRunning;
|
||||
bool m_bWaiting;
|
||||
bool m_bEnding;
|
||||
bool m_bInit;
|
||||
ENode * m_pTarget;
|
||||
EScene * m_pParentScene;
|
||||
LONGLONG m_nAnimationInterval;
|
||||
std::chrono::steady_clock::time_point m_nLast;
|
||||
};
|
||||
|
||||
|
||||
class Animation :
|
||||
public EAction
|
||||
{
|
||||
public:
|
||||
Animation(float duration);
|
||||
virtual ~Animation();
|
||||
|
||||
protected:
|
||||
LONGLONG m_nDuration;
|
||||
LONGLONG m_nTotalDuration;
|
||||
|
||||
protected:
|
||||
bool _isEnd() const;
|
||||
bool _isDelayEnough();
|
||||
virtual void _init() override;
|
||||
virtual void _reset() override;
|
||||
};
|
||||
|
||||
|
||||
class ActionMoveBy :
|
||||
public Animation
|
||||
{
|
||||
public:
|
||||
ActionMoveBy(float duration, EVec vector);
|
||||
virtual ~ActionMoveBy();
|
||||
|
||||
virtual ActionMoveBy * copy() const override;
|
||||
virtual ActionMoveBy * reverse() const override;
|
||||
|
||||
protected:
|
||||
EPoint m_BeginPos;
|
||||
EVec m_MoveVector;
|
||||
|
||||
protected:
|
||||
virtual void _init() override;
|
||||
virtual void _exec() override;
|
||||
virtual void _reset() override;
|
||||
};
|
||||
|
||||
|
||||
class ActionMoveTo :
|
||||
public ActionMoveBy
|
||||
{
|
||||
public:
|
||||
ActionMoveTo(float duration, EPoint pos);
|
||||
virtual ~ActionMoveTo();
|
||||
|
||||
virtual ActionMoveTo * copy() const override;
|
||||
|
||||
protected:
|
||||
EPoint m_EndPos;
|
||||
|
||||
protected:
|
||||
virtual void _init() override;
|
||||
virtual void _reset() override;
|
||||
};
|
||||
|
||||
|
||||
class ActionScaleBy :
|
||||
public Animation
|
||||
{
|
||||
public:
|
||||
ActionScaleBy(float duration, float scaleX, float scaleY);
|
||||
virtual ~ActionScaleBy();
|
||||
|
||||
virtual ActionScaleBy * copy() const override;
|
||||
virtual ActionScaleBy * reverse() const override;
|
||||
|
||||
protected:
|
||||
float m_nBeginScaleX;
|
||||
float m_nBeginScaleY;
|
||||
float m_nVariationX;
|
||||
float m_nVariationY;
|
||||
|
||||
protected:
|
||||
virtual void _init() override;
|
||||
virtual void _exec() override;
|
||||
virtual void _reset() override;
|
||||
};
|
||||
|
||||
|
||||
class ActionScaleTo :
|
||||
public ActionScaleBy
|
||||
{
|
||||
public:
|
||||
ActionScaleTo(float duration, float scaleX, float scaleY);
|
||||
virtual ~ActionScaleTo();
|
||||
|
||||
virtual ActionScaleTo * copy() const override;
|
||||
|
||||
protected:
|
||||
float m_nEndScaleX;
|
||||
float m_nEndScaleY;
|
||||
|
||||
protected:
|
||||
virtual void _init() override;
|
||||
virtual void _reset() override;
|
||||
};
|
||||
|
||||
|
||||
class ActionOpacityBy :
|
||||
public Animation
|
||||
{
|
||||
public:
|
||||
ActionOpacityBy(float duration, float opacity);
|
||||
virtual ~ActionOpacityBy();
|
||||
|
||||
virtual ActionOpacityBy * copy() const override;
|
||||
virtual ActionOpacityBy * reverse() const override;
|
||||
|
||||
protected:
|
||||
float m_nBeginVal;
|
||||
float m_nVariation;
|
||||
|
||||
protected:
|
||||
virtual void _init() override;
|
||||
virtual void _exec() override;
|
||||
virtual void _reset() override;
|
||||
};
|
||||
|
||||
|
||||
class ActionOpacityTo :
|
||||
public ActionOpacityBy
|
||||
{
|
||||
public:
|
||||
ActionOpacityTo(float duration, float opacity);
|
||||
virtual ~ActionOpacityTo();
|
||||
|
||||
virtual ActionOpacityTo * copy() const override;
|
||||
|
||||
protected:
|
||||
float m_nEndVal;
|
||||
|
||||
protected:
|
||||
virtual void _init() override;
|
||||
virtual void _reset() override;
|
||||
};
|
||||
|
||||
|
||||
class ActionFadeIn :
|
||||
public ActionOpacityTo
|
||||
{
|
||||
public:
|
||||
ActionFadeIn(float duration) : ActionOpacityTo(duration, 1) {}
|
||||
};
|
||||
|
||||
|
||||
class ActionFadeOut :
|
||||
public ActionOpacityTo
|
||||
{
|
||||
public:
|
||||
ActionFadeOut(float duration) : ActionOpacityTo(duration, 0) {}
|
||||
};
|
||||
|
||||
|
||||
class ActionTwo :
|
||||
public EAction
|
||||
{
|
||||
public:
|
||||
ActionTwo(EAction * actionFirst, EAction * actionSecond);
|
||||
virtual ~ActionTwo();
|
||||
|
||||
virtual ActionTwo * copy() const override;
|
||||
virtual ActionTwo * reverse(bool actionReverse = true) const;
|
||||
|
||||
protected:
|
||||
EAction * m_FirstAction;
|
||||
EAction * m_SecondAction;
|
||||
|
||||
protected:
|
||||
virtual void _init() override;
|
||||
virtual void _exec() override;
|
||||
virtual void _reset() override;
|
||||
};
|
||||
|
||||
|
||||
class ActionSequence :
|
||||
public EAction
|
||||
{
|
||||
public:
|
||||
ActionSequence();
|
||||
ActionSequence(int number, EAction * action1, ...);
|
||||
virtual ~ActionSequence();
|
||||
|
||||
void addAction(EAction * action);
|
||||
virtual ActionSequence * copy() const override;
|
||||
virtual ActionSequence * reverse(bool actionReverse = true) const;
|
||||
|
||||
protected:
|
||||
UINT m_nActionIndex;
|
||||
std::vector<EAction*> m_vActions;
|
||||
|
||||
protected:
|
||||
virtual void _init() override;
|
||||
virtual void _exec() override;
|
||||
virtual void _reset() override;
|
||||
};
|
||||
|
||||
|
||||
class ActionDelay :
|
||||
public EAction
|
||||
{
|
||||
public:
|
||||
ActionDelay(float duration);
|
||||
virtual ~ActionDelay();
|
||||
|
||||
virtual ActionDelay * copy() const override;
|
||||
|
||||
protected:
|
||||
virtual void _init() override;
|
||||
virtual void _exec() override;
|
||||
virtual void _reset() override;
|
||||
};
|
||||
|
||||
|
||||
class ActionNeverStop :
|
||||
public EAction
|
||||
{
|
||||
public:
|
||||
ActionNeverStop(EAction * action);
|
||||
virtual ~ActionNeverStop();
|
||||
|
||||
virtual ActionNeverStop * copy() const override;
|
||||
|
||||
protected:
|
||||
EAction * m_Action;
|
||||
|
||||
protected:
|
||||
virtual void _init() override;
|
||||
virtual void _exec() override;
|
||||
virtual void _reset() override;
|
||||
};
|
||||
|
||||
|
||||
class ActionFrames :
|
||||
public EAction
|
||||
{
|
||||
public:
|
||||
ActionFrames();
|
||||
ActionFrames(LONGLONG frameDelay);
|
||||
~ActionFrames();
|
||||
|
||||
void addFrame(Image * frame);
|
||||
virtual ActionFrames * copy() const override;
|
||||
virtual ActionFrames * reverse() const override;
|
||||
|
||||
protected:
|
||||
UINT m_nFrameIndex;
|
||||
EVector<Image*> m_vFrames;
|
||||
|
||||
protected:
|
||||
virtual void _init() override;
|
||||
virtual void _exec() override;
|
||||
virtual void _reset() override;
|
||||
};
|
||||
|
||||
|
||||
class ActionCallback :
|
||||
public EAction
|
||||
{
|
||||
public:
|
||||
ActionCallback(const std::function<void()>& callback);
|
||||
~ActionCallback();
|
||||
|
||||
virtual ActionCallback * copy() const override;
|
||||
|
||||
protected:
|
||||
std::function<void()> m_Callback;
|
||||
|
||||
protected:
|
||||
virtual void _init() override;
|
||||
virtual void _exec() override;
|
||||
virtual void _reset() override;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -22,6 +22,7 @@
|
|||
#include "enodes.h"
|
||||
#include "emsg.h"
|
||||
#include "etools.h"
|
||||
#include "eactions.h"
|
||||
|
||||
|
||||
#if defined(DEBUG) || defined(_DEBUG)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class EApp
|
|||
public:
|
||||
EApp();
|
||||
|
||||
~EApp();
|
||||
virtual ~EApp();
|
||||
|
||||
// 初始化游戏界面
|
||||
bool init(
|
||||
|
|
@ -193,7 +193,7 @@ class EScene
|
|||
public:
|
||||
EScene();
|
||||
|
||||
~EScene();
|
||||
virtual ~EScene();
|
||||
|
||||
// 重写这个函数,它将在进入这个场景时自动执行
|
||||
virtual void onEnter();
|
||||
|
|
|
|||
|
|
@ -194,7 +194,7 @@ protected:
|
|||
void _notify();
|
||||
|
||||
// 执行监听器回调函数
|
||||
virtual void _runCallback() = 0;
|
||||
virtual void _callOn() = 0;
|
||||
|
||||
protected:
|
||||
EString m_sName;
|
||||
|
|
@ -244,7 +244,7 @@ public:
|
|||
|
||||
protected:
|
||||
// 执行监听器回调函数
|
||||
virtual void _runCallback() override;
|
||||
virtual void _callOn() override;
|
||||
|
||||
protected:
|
||||
MOUSE_LISTENER_CALLBACK m_Callback;
|
||||
|
|
@ -278,7 +278,7 @@ public:
|
|||
|
||||
protected:
|
||||
// 执行监听器回调函数
|
||||
virtual void _runCallback() override;
|
||||
virtual void _callOn() override;
|
||||
|
||||
protected:
|
||||
MOUSE_PRESS_LISTENER_CALLBACK m_Callback;
|
||||
|
|
@ -312,7 +312,7 @@ public:
|
|||
|
||||
protected:
|
||||
// 执行监听器回调函数
|
||||
virtual void _runCallback() override;
|
||||
virtual void _callOn() override;
|
||||
|
||||
protected:
|
||||
bool m_bPressed;
|
||||
|
|
@ -347,7 +347,7 @@ public:
|
|||
|
||||
protected:
|
||||
// 执行监听器回调函数
|
||||
virtual void _runCallback() override;
|
||||
virtual void _callOn() override;
|
||||
|
||||
protected:
|
||||
bool m_bPressed;
|
||||
|
|
@ -382,7 +382,7 @@ public:
|
|||
|
||||
protected:
|
||||
// 执行监听器回调函数
|
||||
virtual void _runCallback() override;
|
||||
virtual void _callOn() override;
|
||||
|
||||
protected:
|
||||
EPoint m_Begin;
|
||||
|
|
@ -429,7 +429,7 @@ public:
|
|||
|
||||
protected:
|
||||
// 执行监听器回调函数
|
||||
virtual void _runCallback() override;
|
||||
virtual void _callOn() override;
|
||||
|
||||
protected:
|
||||
KEY_LISTENER_CALLBACK m_Callback;
|
||||
|
|
@ -460,7 +460,7 @@ public:
|
|||
|
||||
protected:
|
||||
// 执行监听器回调函数
|
||||
virtual void _runCallback() override;
|
||||
virtual void _callOn() override;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ namespace e2d
|
|||
|
||||
class EText;
|
||||
class ESprite;
|
||||
class EAction;
|
||||
|
||||
class ENode :
|
||||
public EObject
|
||||
|
|
@ -240,18 +241,28 @@ public:
|
|||
// 移除子节点
|
||||
virtual bool removeChild(
|
||||
ENode * child,
|
||||
bool release = false
|
||||
bool release = true
|
||||
);
|
||||
|
||||
// 移除子节点
|
||||
virtual void removeChild(
|
||||
const EString & childName,
|
||||
bool release = false
|
||||
bool release = true
|
||||
);
|
||||
|
||||
// 移除所有节点
|
||||
virtual void clearAllChildren(
|
||||
bool release = false
|
||||
bool release = true
|
||||
);
|
||||
|
||||
// 执行动画
|
||||
virtual void runAction(
|
||||
EAction * action
|
||||
);
|
||||
|
||||
// 停止动画
|
||||
virtual void stopAction(
|
||||
EAction * action
|
||||
);
|
||||
|
||||
protected:
|
||||
|
|
@ -267,9 +278,6 @@ protected:
|
|||
// 节点从场景中消失时的执行程序
|
||||
virtual void _onExit();
|
||||
|
||||
// 节点清除时的执行程序
|
||||
virtual void _onClear();
|
||||
|
||||
// 子节点排序
|
||||
void _sortChildren();
|
||||
|
||||
|
|
@ -336,7 +344,7 @@ protected:
|
|||
EScene * m_pParentScene;
|
||||
ENode * m_pParent;
|
||||
D2D1::Matrix3x2F m_Matri;
|
||||
EVector<ENode*> m_vChildren;
|
||||
EVector<ENode*> m_vChildren;
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -360,7 +368,7 @@ public:
|
|||
const EString & resourceType
|
||||
);
|
||||
|
||||
~ETexture();
|
||||
virtual ~ETexture();
|
||||
|
||||
// 从本地文件中读取资源
|
||||
void loadFromFile(
|
||||
|
|
@ -441,7 +449,7 @@ public:
|
|||
float height
|
||||
);
|
||||
|
||||
~ESprite();
|
||||
virtual ~ESprite();
|
||||
|
||||
// 设置精灵纹理
|
||||
void setTexture(
|
||||
|
|
@ -491,7 +499,7 @@ public:
|
|||
bool italic = false
|
||||
);
|
||||
|
||||
~EFont();
|
||||
virtual ~EFont();
|
||||
|
||||
// 获取当前字号
|
||||
float getFontSize() const;
|
||||
|
|
@ -568,7 +576,7 @@ public:
|
|||
bool italic = false
|
||||
);
|
||||
|
||||
~EText();
|
||||
virtual ~EText();
|
||||
|
||||
// 获取文本
|
||||
EString getText() const;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ namespace e2d
|
|||
{
|
||||
|
||||
class ETimerManager;
|
||||
class EAction;
|
||||
|
||||
// 对象管理器
|
||||
class EObjectManager
|
||||
|
|
@ -103,7 +104,7 @@ protected:
|
|||
void _notify();
|
||||
|
||||
// 执行回调函数
|
||||
virtual void _runCallback();
|
||||
virtual void _callOn();
|
||||
|
||||
protected:
|
||||
EString m_sName;
|
||||
|
|
@ -217,4 +218,83 @@ private:
|
|||
static void TimerProc();
|
||||
};
|
||||
|
||||
|
||||
// 动作管理器
|
||||
class EActionManager
|
||||
{
|
||||
friend EApp;
|
||||
friend EScene;
|
||||
friend ENode;
|
||||
|
||||
public:
|
||||
// 绑定动作到节点
|
||||
static void bindAction(
|
||||
EAction * action,
|
||||
ENode * pParentNode
|
||||
);
|
||||
|
||||
// 启动绑定在场景子节点上的所有动作
|
||||
static void startAllActionsBindedWith(
|
||||
EScene * pParentScene
|
||||
);
|
||||
|
||||
// 停止绑定在场景子节点上的所有动作
|
||||
static void stopAllActionsBindedWith(
|
||||
EScene * pParentScene
|
||||
);
|
||||
|
||||
// 清空绑定在场景子节点上的所有动作
|
||||
static void clearAllActionsBindedWith(
|
||||
EScene * pParentScene
|
||||
);
|
||||
|
||||
// 启动绑定在节点上的所有动作
|
||||
static void startAllActionsBindedWith(
|
||||
ENode * pParentNode
|
||||
);
|
||||
|
||||
// 停止绑定在节点上的所有动作
|
||||
static void stopAllActionsBindedWith(
|
||||
ENode * pParentNode
|
||||
);
|
||||
|
||||
// 清空绑定在节点上的所有动作
|
||||
static void clearAllActionsBindedWith(
|
||||
ENode * pParentNode
|
||||
);
|
||||
|
||||
// 启动所有动作
|
||||
static void startAllActions();
|
||||
|
||||
// 停止所有动作
|
||||
static void stopAllActions();
|
||||
|
||||
// 清除所有动作
|
||||
static void clearAllActions();
|
||||
|
||||
private:
|
||||
// 挂起绑定在场景子节点上的所有动作
|
||||
static void _waitAllActionsBindedWith(
|
||||
EScene * pParentScene
|
||||
);
|
||||
|
||||
// 重启绑定在场景子节点上的所有动作
|
||||
static void _notifyAllActionsBindedWith(
|
||||
EScene * pParentScene
|
||||
);
|
||||
|
||||
// 挂起绑定在节点上的所有动作
|
||||
static void _waitAllActionsBindedWith(
|
||||
ENode * pParentNode
|
||||
);
|
||||
|
||||
// 重启绑定在节点上的所有动作
|
||||
static void _notifyAllActionsBindedWith(
|
||||
ENode * pParentNode
|
||||
);
|
||||
|
||||
// 动作执行程序
|
||||
static void ActionProc();
|
||||
};
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue