新增Animate类;细节调整

This commit is contained in:
Nomango 2018-05-10 00:58:43 +08:00
parent 4a62b2a5bf
commit f66a56e028
25 changed files with 633 additions and 479 deletions

View File

@ -21,7 +21,7 @@ void e2d::ActionGradual::_update()
this->stop();
return;
}
// 计算动进度
// 计算动进度
_delta = min((Time::getTotalTime() - _last) / _duration, 1);
// 判断动作是否结束
if (_delta >= 1)

114
core/Action/Animate.cpp Normal file
View File

@ -0,0 +1,114 @@
#include "..\e2daction.h"
e2d::Animate::Animate()
: _frameIndex(0)
, _animation(nullptr)
{
}
e2d::Animate::Animate(Animation * animation)
: _frameIndex(0)
, _animation(nullptr)
{
this->setAnimation(animation);
}
e2d::Animate::~Animate()
{
}
e2d::Animation * e2d::Animate::getAnimation() const
{
return _animation;
}
void e2d::Animate::setAnimation(Animation * animation)
{
if (animation && animation != _animation)
{
SafeRelease(&_animation);
_animation = animation;
_animation->retain();
}
}
void e2d::Animate::_init()
{
Action::_init();
auto target = dynamic_cast<Sprite*>(_target);
if (target && _animation)
{
target->open(_animation->getFrames()[_frameIndex]);
++_frameIndex;
}
}
void e2d::Animate::_update()
{
Action::_update();
if (!_animation)
{
this->stop();
return;
}
while ((Time::getTotalTime() - _last) >= _animation->getInterval())
{
auto& frames = _animation->getFrames();
auto target = dynamic_cast<Sprite*>(_target);
if (target)
{
target->open(frames[_frameIndex]);
}
_last += _animation->getInterval();
_frameIndex++;
if (_frameIndex == frames.size())
{
this->stop();
break;
}
}
}
void e2d::Animate::reset()
{
Action::reset();
_frameIndex = 0;
}
void e2d::Animate::onDestroy()
{
Action::onDestroy();
SafeRelease(&_animation);
}
e2d::Animate * e2d::Animate::clone() const
{
return new (std::nothrow) Animate(_animation);
}
e2d::Animate * e2d::Animate::reverse() const
{
auto& oldFrames = _animation->getFrames();
std::vector<Image*> frames(oldFrames.size());
if (!oldFrames.empty())
{
for (auto iter = oldFrames.crbegin(), iterCrend = oldFrames.crend(); iter != iterCrend; ++iter)
{
Image* frame = *iter;
if (frame)
{
frames.push_back(frame);
}
}
}
auto animation = new (std::nothrow) Animation(_animation->getInterval(), frames);
return new (std::nothrow) Animate(animation);
}

View File

@ -1,168 +0,0 @@
#include "..\e2daction.h"
e2d::Animation::Animation()
: _frameIndex(0)
, _interval(1)
{
}
e2d::Animation::Animation(double interval)
: _frameIndex(0)
, _interval(interval)
{
}
#ifdef HIGHER_THAN_VS2012
e2d::Animation::Animation(const std::initializer_list<Image*>& vImages)
: _frameIndex(0)
, _interval(1)
{
this->add(vImages);
}
e2d::Animation::Animation(double interval, const std::initializer_list<Image*>& vImages)
: _frameIndex(0)
, _interval(interval)
{
this->add(vImages);
}
#else
e2d::Animation::Animation(int number, Image * frame, ...)
: _frameIndex(0)
, _interval(1)
{
Image ** ppImage = &frame;
while (number > 0)
{
WARN_IF((*ppImage) == nullptr, "Animation NULL pointer exception!");
this->add(*ppImage);
ppImage++;
number--;
}
}
e2d::Animation::Animation(double interval, int number, Image * frame, ...)
: _frameIndex(0)
, _interval(interval)
{
Image ** ppImage = &frame;
while (number > 0)
{
WARN_IF((*ppImage) == nullptr, "Animation NULL pointer exception!");
this->add(*ppImage);
ppImage++;
number--;
}
}
#endif
e2d::Animation::~Animation()
{
}
void e2d::Animation::setInterval(double interval)
{
_interval = max(interval, 0);
}
void e2d::Animation::_init()
{
Action::_init();
}
void e2d::Animation::_update()
{
Action::_update();
if (_target == nullptr)
{
this->stop();
return;
}
// 判断时间间隔是否足够
while ((Time::getTotalTime() - _last) >= _interval)
{
// 重新记录时间
_last += _interval;
// 加载关键帧
static_cast<Sprite*>(_target)->open(_frames[_frameIndex]);
_frameIndex++;
// 判断动作是否结束
if (_frameIndex == _frames.size())
{
this->stop();
break;
}
}
}
void e2d::Animation::reset()
{
Action::reset();
_frameIndex = 0;
}
void e2d::Animation::onDestroy()
{
Action::onDestroy();
for (auto frame : _frames)
{
SafeRelease(&frame);
}
}
void e2d::Animation::add(Image * frame)
{
if (frame)
{
_frames.push_back(frame);
frame->retain();
}
}
#ifdef HIGHER_THAN_VS2012
void e2d::Animation::add(const std::initializer_list<Image*>& vImages)
{
for (const auto &image : vImages)
{
this->add(image);
}
}
#else
void e2d::Animation::add(int number, Image * frame, ...)
{
Image ** ppImage = &frame;
while (number > 0)
{
WARN_IF((*ppImage) == nullptr, "Animation NULL pointer exception!");
this->add(*ppImage);
ppImage++;
number--;
}
}
#endif
e2d::Animation * e2d::Animation::clone() const
{
auto a = new Animation(_interval);
for (auto frame : _frames)
{
a->add(frame);
}
return a;
}
e2d::Animation * e2d::Animation::reverse() const
{
auto a = this->clone();
a->_frames.reserve(_frames.size());
return a;
}

View File

@ -10,6 +10,7 @@ e2d::MoveBy::MoveBy(double duration, Vector vector) :
void e2d::MoveBy::_init()
{
ActionGradual::_init();
if (_target)
{
_startPos = _target->getPos();
@ -20,14 +21,11 @@ void e2d::MoveBy::_update()
{
ActionGradual::_update();
if (_target == nullptr)
if (_target)
{
this->stop();
return;
}
_target->setPos(_startPos + _deltaPos * _delta);
}
}
e2d::MoveBy * e2d::MoveBy::clone() const
{

View File

@ -10,6 +10,7 @@ e2d::OpacityBy::OpacityBy(double duration, double opacity) :
void e2d::OpacityBy::_init()
{
ActionGradual::_init();
if (_target)
{
_startVal = _target->getOpacity();
@ -20,14 +21,11 @@ void e2d::OpacityBy::_update()
{
ActionGradual::_update();
if (_target == nullptr)
if (_target)
{
this->stop();
return;
}
_target->setOpacity(_startVal + _deltaVal * _delta);
}
}
e2d::OpacityBy * e2d::OpacityBy::clone() const
{

View File

@ -10,6 +10,7 @@ e2d::RotateBy::RotateBy(double duration, double rotation) :
void e2d::RotateBy::_init()
{
ActionGradual::_init();
if (_target)
{
_startVal = _target->getRotation();
@ -20,14 +21,11 @@ void e2d::RotateBy::_update()
{
ActionGradual::_update();
if (_target == nullptr)
if (_target)
{
this->stop();
return;
}
_target->setRotation(_startVal + _deltaVal * _delta);
}
}
e2d::RotateBy * e2d::RotateBy::clone() const
{

View File

@ -18,6 +18,7 @@ e2d::ScaleBy::ScaleBy(double duration, double scaleX, double scaleY)
void e2d::ScaleBy::_init()
{
ActionGradual::_init();
if (_target)
{
_startScaleX = _target->getScaleX();
@ -29,14 +30,11 @@ void e2d::ScaleBy::_update()
{
ActionGradual::_update();
if (_target == nullptr)
if (_target)
{
this->stop();
return;
}
_target->setScale(_startScaleX + _deltaX * _delta, _startScaleY + _deltaY * _delta);
}
}
e2d::ScaleBy * e2d::ScaleBy::clone() const
{

View File

@ -5,25 +5,26 @@ e2d::Sequence::Sequence()
{
}
#ifdef HIGHER_THAN_VS2012
e2d::Sequence::Sequence(const std::initializer_list<Action*>& vActions)
: _currIndex(0)
{
this->add(vActions);
}
#else
e2d::Sequence::Sequence(int number, Action * action1, ...) :
e2d::Sequence::Sequence(int number, Action * action, ...) :
_currIndex(0)
{
Action ** ppAction = &action1;
va_list args;
va_start(args, action);
while (number > 0)
this->add(action);
for (int i = 1; i < number; i++)
{
WARN_IF((*ppAction) == nullptr, "Sequence NULL pointer exception!");
this->add(*ppAction);
ppAction++;
number--;
this->add(va_arg(args, Action*));
}
va_end(args);
}
#ifdef HIGHER_THAN_VS2012
e2d::Sequence::Sequence(const std::initializer_list<Action*>& actions)
: _currIndex(0)
{
this->add(actions);
}
#endif
@ -103,25 +104,26 @@ void e2d::Sequence::add(Action * action)
}
}
#ifdef HIGHER_THAN_VS2012
void e2d::Sequence::add(const std::initializer_list<Action*>& vActions)
{
for (const auto &action : vActions)
{
this->add(action);
}
}
#else
void e2d::Sequence::add(int number, Action * action, ...)
{
Action ** ppAction = &action;
va_list args;
va_start(args, action);
while (number > 0)
this->add(action);
for (int i = 1; i < number; i++)
{
WARN_IF((*ppAction) == nullptr, "Sequence NULL pointer exception!");
this->add(*ppAction);
ppAction++;
number--;
this->add(va_arg(args, Action*));
}
va_end(args);
}
#ifdef HIGHER_THAN_VS2012
void e2d::Sequence::add(const std::initializer_list<Action*>& actions)
{
for (const auto &action : actions)
{
this->add(action);
}
}
#endif

View File

@ -4,24 +4,24 @@ e2d::Spawn::Spawn()
{
}
#ifdef HIGHER_THAN_VS2012
e2d::Spawn::Spawn(const std::initializer_list<Action*>& vActions)
e2d::Spawn::Spawn(int number, Action * action, ...)
{
this->add(vActions);
}
#else
e2d::Spawn::Spawn(int number, Action * action1, ...) :
_currIndex(0)
{
Action ** ppAction = &action1;
va_list args;
va_start(args, action);
while (number > 0)
this->add(action);
for (int i = 1; i < number; i++)
{
WARN_IF((*ppAction) == nullptr, "Spawn NULL pointer exception!");
this->add(*ppAction);
ppAction++;
number--;
this->add(va_arg(args, Action*));
}
va_end(args);
}
#ifdef HIGHER_THAN_VS2012
e2d::Spawn::Spawn(const std::initializer_list<Action*>& actions)
{
this->add(actions);
}
#endif
@ -101,25 +101,26 @@ void e2d::Spawn::add(Action * action)
}
}
#ifdef HIGHER_THAN_VS2012
void e2d::Spawn::add(const std::initializer_list<Action*>& vActions)
{
for (const auto &action : vActions)
{
this->add(action);
}
}
#else
void e2d::Spawn::add(int number, Action * action, ...)
{
Action ** ppAction = &action;
va_list args;
va_start(args, action);
while (number > 0)
this->add(action);
for (int i = 1; i < number; i++)
{
WARN_IF((*ppAction) == nullptr, "Spawn NULL pointer exception!");
this->add(*ppAction);
ppAction++;
number--;
this->add(va_arg(args, Action*));
}
va_end(args);
}
#ifdef HIGHER_THAN_VS2012
void e2d::Spawn::add(const std::initializer_list<Action*>& actions)
{
for (const auto &action : actions)
{
this->add(action);
}
}
#endif

View File

@ -154,7 +154,7 @@ void e2d::Game::resume()
s_bPaused = false;
// 刷新当前时间
Time::__updateLast();
// 重置动和定时器
// 重置动和定时器
ActionManager::__resetAll();
Timer::__resetAll();
}
@ -177,7 +177,7 @@ void e2d::Game::destroy()
// 删除监听器
InputManager::__uninit();
ColliderManager::__uninit();
// 删除动
// 删除动
ActionManager::__uninit();
// 删除所有对象
ObjectManager::__clear();

139
core/Common/Animation.cpp Normal file
View File

@ -0,0 +1,139 @@
#include "..\e2dcommon.h"
e2d::Animation::Animation()
: _interval(1)
{
}
e2d::Animation::Animation(double interval)
: _interval(interval)
{
}
e2d::Animation::Animation(double interval, const std::vector<Image*>& frames)
: _interval(interval)
{
for (auto frame : frames)
{
this->add(frame);
}
}
e2d::Animation::Animation(int number, Image * frame, ...)
: _interval(1)
{
va_list args;
va_start(args, frame);
this->add(frame);
for (int i = 1; i < number; i++)
{
this->add(va_arg(args, Image*));
}
va_end(args);
}
e2d::Animation::Animation(double interval, int number, Image * frame, ...)
: _interval(interval)
{
va_list args;
va_start(args, frame);
this->add(frame);
for (int i = 1; i < number; i++)
{
this->add(va_arg(args, Image*));
}
va_end(args);
}
#ifdef HIGHER_THAN_VS2012
e2d::Animation::Animation(const std::initializer_list<Image*>& frames)
: _interval(1)
{
this->add(frames);
}
e2d::Animation::Animation(double interval, const std::initializer_list<Image*>& frames)
: _interval(interval)
{
this->add(frames);
}
#endif
e2d::Animation::~Animation()
{
}
void e2d::Animation::setInterval(double interval)
{
_interval = max(interval, 0);
}
void e2d::Animation::onDestroy()
{
for (auto frame : _frames)
{
SafeRelease(&frame);
}
}
void e2d::Animation::add(Image * frame)
{
if (frame)
{
_frames.push_back(frame);
frame->retain();
}
}
void e2d::Animation::add(int number, Image * frame, ...)
{
va_list args;
va_start(args, frame);
this->add(frame);
--number;
while (number > 0)
{
this->add(va_arg(args, Image*));
--number;
}
va_end(args);
}
#ifdef HIGHER_THAN_VS2012
void e2d::Animation::add(const std::initializer_list<Image*>& frames)
{
for (const auto &image : frames)
{
this->add(image);
}
}
#endif
double e2d::Animation::getInterval() const
{
return _interval;
}
const std::vector<e2d::Image*>& e2d::Animation::getFrames() const
{
return _frames;
}
e2d::Animation * e2d::Animation::clone() const
{
auto a = new Animation(_interval);
for (auto frame : _frames)
{
a->add(frame);
}
return a;
}

View File

@ -192,6 +192,7 @@ bool e2d::Image::preload(const String& fileName)
// (DXGI_FORMAT_B8G8R8A8_UNORM + D2D1_ALPHA_MODE_PREMULTIPLIED).
hr = Renderer::getIWICImagingFactory()->CreateFormatConverter(&pConverter);
}
if (SUCCEEDED(hr))
{
// 图片格式转换成 32bbpPBGRA
@ -204,6 +205,7 @@ bool e2d::Image::preload(const String& fileName)
WICBitmapPaletteTypeMedianCut
);
}
if (SUCCEEDED(hr))
{
// 从 WIC 位图创建一个 Direct2D 位图
@ -213,6 +215,7 @@ bool e2d::Image::preload(const String& fileName)
&pBitmap
);
}
if (SUCCEEDED(hr))
{
// 保存图片指针和图片的 Hash 名

View File

@ -50,9 +50,9 @@ void e2d::Scene::add(Node * child, int order /* = 0 */)
}
#ifdef HIGHER_THAN_VS2012
void e2d::Scene::add(const std::initializer_list<Node*>& vNodes, int order)
void e2d::Scene::add(const std::initializer_list<Node*>& nodes, int order)
{
for (const auto &node : vNodes)
for (const auto &node : nodes)
{
this->add(node, order);
}

View File

@ -213,15 +213,15 @@ void e2d::ActionManager::stopAll()
std::vector<e2d::Action*> e2d::ActionManager::get(const String& strActionName)
{
std::vector<Action*> vActions;
std::vector<Action*> actions;
for (auto action : s_vActions)
{
if (action->getName() == strActionName)
{
vActions.push_back(action);
actions.push_back(action);
}
}
return std::move(vActions);
return std::move(actions);
}
std::vector<e2d::Action*> e2d::ActionManager::getAll()

View File

@ -16,7 +16,7 @@ void e2d::SceneManager::enter(Scene * scene, Transition * transition /* = nullpt
// 保存下一场景的指针
s_pNextScene = scene;
// 设置切换场景动
// 设置切换场景动
if (transition)
{
if (s_pTransition)
@ -52,7 +52,7 @@ void e2d::SceneManager::back(Transition * transition /* = nullptr */)
s_bSaveCurrScene = false;
}
// 设置切换场景动
// 设置切换场景动
if (transition)
{
s_pTransition = transition;
@ -100,7 +100,7 @@ void e2d::SceneManager::__update()
}
else
{
// 更新场景动
// 更新场景动
s_pTransition->_update();
if (s_pTransition->isDone())

View File

@ -5,6 +5,21 @@ e2d::Menu::Menu()
{
}
e2d::Menu::Menu(int number, Button * button1, ...)
: _enable(true)
{
va_list args;
va_start(args, button1);
this->addButton(button1);
for (int i = 1; i < number; i++)
{
this->addButton(va_arg(args, Button*));
}
va_end(args);
}
#ifdef HIGHER_THAN_VS2012
e2d::Menu::Menu(const std::initializer_list<Button*>& vButtons)
: _enable(true)
@ -14,21 +29,6 @@ e2d::Menu::Menu(const std::initializer_list<Button*>& vButtons)
this->addButton(button);
}
}
#else
e2d::Menu::Menu(int number, Button * button1, ...)
: _enable(true)
{
Button ** ppButton = &button1;
while (number > 0)
{
this->addButton(*ppButton);
ppButton++;
number--;
}
}
#endif
bool e2d::Menu::isEnable() const

View File

@ -597,10 +597,24 @@ void e2d::Node::addColliableName(const String& collliderName)
_colliders.insert(hash);
}
#ifdef HIGHER_THAN_VS2012
void e2d::Node::addColliableName(const std::initializer_list<String>& vCollliderName)
void e2d::Node::addColliableName(int number, String collliderName, ...)
{
for (const auto &name : vCollliderName)
va_list args;
va_start(args, collliderName);
this->addColliableName(collliderName);
for (int i = 1; i < number; i++)
{
this->addColliableName(va_arg(args, String));
}
va_end(args);
}
#ifdef HIGHER_THAN_VS2012
void e2d::Node::addColliableName(const std::initializer_list<String>& colliderNames)
{
for (const auto &name : colliderNames)
{
this->addColliableName(name);
}
@ -649,9 +663,9 @@ void e2d::Node::addChild(Node * child, int order /* = 0 */)
}
#ifdef HIGHER_THAN_VS2012
void e2d::Node::addChild(const std::initializer_list<Node*>& vNodes, int order)
void e2d::Node::addChild(const std::initializer_list<Node*>& nodes, int order)
{
for (const auto &node : vNodes)
for (const auto &node : nodes)
{
this->addChild(node, order);
}

View File

@ -60,7 +60,7 @@ void e2d::Transition::_init(Scene * prev, Scene * next)
void e2d::Transition::_update()
{
// 计算动进度
// 计算动进度
if (_duration == 0)
{
_delta = 1;

View File

@ -70,7 +70,7 @@ protected:
// 获取动作结束状态
virtual bool _isDone();
// 重置动时间
// 重置动时间
virtual void _resetTime();
// 开始动作
@ -93,16 +93,16 @@ class ActionGradual :
public Action
{
public:
// 创建特定时长的持续动
// 创建特定时长的持续动
ActionGradual(
double duration
);
protected:
// 初始化动
// 初始化动
virtual void _init() override;
// 更新动
// 更新动
virtual void _update() override;
protected:
@ -111,28 +111,28 @@ protected:
};
// 相对位移动
// 相对位移动
class MoveBy :
public ActionGradual
{
public:
// 创建相对位移动
// 创建相对位移动
MoveBy(
double duration, /* 动持续时长 */
double duration, /* 动持续时长 */
Vector vector /* 位移向量 */
);
// 获取该动的拷贝对象
// 获取该动的拷贝对象
virtual MoveBy * clone() const override;
// 获取该动的倒转
// 获取该动的倒转
virtual MoveBy * reverse() const override;
protected:
// 初始化动
// 初始化动
virtual void _init() override;
// 执行动
// 执行动
virtual void _update() override;
protected:
@ -141,22 +141,22 @@ protected:
};
// 位移动
// 位移动
class MoveTo :
public MoveBy
{
public:
// 创建位移动
// 创建位移动
MoveTo(
double duration, /* 动持续时长 */
double duration, /* 动持续时长 */
Point pos /* 位移至目标点的坐标 */
);
// 获取该动的拷贝对象
// 获取该动的拷贝对象
virtual MoveTo * clone() const override;
protected:
// 初始化动
// 初始化动
virtual void _init() override;
protected:
@ -164,35 +164,35 @@ protected:
};
// 相对缩放动
// 相对缩放动
class ScaleBy :
public ActionGradual
{
public:
// 创建相对缩放动
// 创建相对缩放动
ScaleBy(
double duration, /* 动持续时长 */
double duration, /* 动持续时长 */
double scale /* 缩放比例变化 */
);
// 创建相对缩放动
// 创建相对缩放动
ScaleBy(
double duration, /* 动持续时长 */
double duration, /* 动持续时长 */
double scaleX, /* 横向缩放比例变化 */
double scaleY /* 纵向缩放比例变化 */
);
// 获取该动的拷贝对象
// 获取该动的拷贝对象
virtual ScaleBy * clone() const override;
// 获取该动的倒转
// 获取该动的倒转
virtual ScaleBy * reverse() const override;
protected:
// 初始化动
// 初始化动
virtual void _init() override;
// 执行动
// 执行动
virtual void _update() override;
protected:
@ -203,29 +203,29 @@ protected:
};
// 缩放动
// 缩放动
class ScaleTo :
public ScaleBy
{
public:
// 创建缩放动
// 创建缩放动
ScaleTo(
double duration, /* 动持续时长 */
double duration, /* 动持续时长 */
double scale /* 缩放至目标比例 */
);
// 创建缩放动
// 创建缩放动
ScaleTo(
double duration, /* 动持续时长 */
double duration, /* 动持续时长 */
double scaleX, /* 横向缩放至目标比例 */
double scaleY /* 纵向缩放至目标比例 */
);
// 获取该动的拷贝对象
// 获取该动的拷贝对象
virtual ScaleTo * clone() const override;
protected:
// 初始化动
// 初始化动
virtual void _init() override;
protected:
@ -234,28 +234,28 @@ protected:
};
// 透明度相对渐变动
// 透明度相对渐变动
class OpacityBy :
public ActionGradual
{
public:
// 创建透明度相对渐变动
// 创建透明度相对渐变动
OpacityBy(
double duration, /* 动持续时长 */
double duration, /* 动持续时长 */
double opacity /* 透明度相对变化值 */
);
// 获取该动的拷贝对象
// 获取该动的拷贝对象
virtual OpacityBy * clone() const override;
// 获取该动的倒转
// 获取该动的倒转
virtual OpacityBy * reverse() const override;
protected:
// 初始化动
// 初始化动
virtual void _init() override;
// 执行动
// 执行动
virtual void _update() override;
protected:
@ -264,22 +264,22 @@ protected:
};
// 透明度渐变动
// 透明度渐变动
class OpacityTo :
public OpacityBy
{
public:
// 创建透明度渐变动
// 创建透明度渐变动
OpacityTo(
double duration, /* 动持续时长 */
double duration, /* 动持续时长 */
double opacity /* 透明度渐变至目标值 */
);
// 获取该动的拷贝对象
// 获取该动的拷贝对象
virtual OpacityTo * clone() const override;
protected:
// 初始化动
// 初始化动
virtual void _init() override;
protected:
@ -287,14 +287,14 @@ protected:
};
// 淡入动
// 淡入动
class FadeIn :
public OpacityTo
{
public:
// 创建淡入动
// 创建淡入动
FadeIn(
double duration /* 动持续时长 */
double duration /* 动持续时长 */
)
: OpacityTo(duration, 1)
{
@ -302,14 +302,14 @@ public:
};
// 淡出动
// 淡出动
class FadeOut :
public OpacityTo
{
public:
// 创建淡出动
// 创建淡出动
FadeOut(
double duration /* 动持续时长 */
double duration /* 动持续时长 */
)
: OpacityTo(duration, 0)
{
@ -322,23 +322,23 @@ class RotateBy :
public ActionGradual
{
public:
// 创建相对旋转动
// 创建相对旋转动
RotateBy(
double duration, /* 动持续时长 */
double duration, /* 动持续时长 */
double rotation /* 旋转角度变化值 */
);
// 获取该动的拷贝对象
// 获取该动的拷贝对象
virtual RotateBy * clone() const override;
// 获取该动的倒转
// 获取该动的倒转
virtual RotateBy * reverse() const override;
protected:
// 初始化动
// 初始化动
virtual void _init() override;
// 执行动
// 执行动
virtual void _update() override;
protected:
@ -352,17 +352,17 @@ class RotateTo :
public RotateBy
{
public:
// 创建旋转动
// 创建旋转动
RotateTo(
double duration, /* 动持续时长 */
double duration, /* 动持续时长 */
double rotation /* 旋转角度至目标值 */
);
// 获取该动的拷贝对象
// 获取该动的拷贝对象
virtual RotateTo * clone() const override;
protected:
// 初始化动
// 初始化动
virtual void _init() override;
protected:
@ -424,7 +424,7 @@ protected:
// 执行动作
virtual void _update() override;
// 重置动时间
// 重置动时间
virtual void _resetTime() override;
protected:
@ -467,18 +467,18 @@ public:
// 创建顺序动作
Sequence();
#ifdef HIGHER_THAN_VS2012
// 创建顺序动作
Sequence(
const std::initializer_list<Action*>& vActions /* 动作列表 */
);
#else
// 创建顺序动作
Sequence(
int number, /* 动作数量 */
Action * action, /* 第一个动作 */
...
);
#ifdef HIGHER_THAN_VS2012
// 创建顺序动作
Sequence(
const std::initializer_list<Action*>& actions /* 动作列表 */
);
#endif
virtual ~Sequence();
@ -488,18 +488,18 @@ public:
Action * action
);
#ifdef HIGHER_THAN_VS2012
// 在结尾添加多个动作
void add(
const std::initializer_list<Action*>& vActions /* 动作列表 */
);
#else
// 在结尾添加多个动作
void add(
int number, /* 动作数量 */
Action * action, /* 第一个动作 */
...
);
#ifdef HIGHER_THAN_VS2012
// 在结尾添加多个动作
void add(
const std::initializer_list<Action*>& actions /* 动作列表 */
);
#endif
// 获取该动作的拷贝对象
@ -521,7 +521,7 @@ protected:
// 执行动作
virtual void _update() override;
// 重置动时间
// 重置动时间
virtual void _resetTime() override;
protected:
@ -538,18 +538,18 @@ public:
// 创建同步动作
Spawn();
#ifdef HIGHER_THAN_VS2012
// 创建同步动作
Spawn(
const std::initializer_list<Action*>& vActions /* 动作列表 */
);
#else
// 创建同步动作
Spawn(
int number, /* 动作数量 */
Action * action, /* 第一个动作 */
...
);
#ifdef HIGHER_THAN_VS2012
// 创建同步动作
Spawn(
const std::initializer_list<Action*>& actions /* 动作列表 */
);
#endif
virtual ~Spawn();
@ -559,18 +559,18 @@ public:
Action * action
);
#ifdef HIGHER_THAN_VS2012
// 在结尾添加多个动作
void add(
const std::initializer_list<Action*>& vActions /* 动作列表 */
);
#else
// 在结尾添加多个动作
void add(
int number, /* 动作数量 */
Action * action, /* 第一个动作 */
...
);
#ifdef HIGHER_THAN_VS2012
// 在结尾添加多个动作
void add(
const std::initializer_list<Action*>& actions /* 动作列表 */
);
#endif
// 获取该动作的拷贝对象
@ -592,7 +592,7 @@ protected:
// 执行动作
virtual void _update() override;
// 重置动时间
// 重置动时间
virtual void _resetTime() override;
protected:
@ -600,78 +600,34 @@ protected:
};
// 帧动画
class Animation :
// 精灵动作
class Animate :
public Action
{
public:
// 创建帧动画
Animation();
// 创建精灵动作
Animate();
// 创建特定帧间隔的帧动画
Animation(
double interval /* 帧间隔(秒) */
// 创建精灵动作
Animate(
Animation * animation
);
#ifdef HIGHER_THAN_VS2012
// 创建帧动画
Animation(
const std::initializer_list<Image*>& vImages /* 关键帧列表 */
virtual ~Animate();
// 获取动画
virtual Animation * getAnimation() const;
// 设置动画
virtual void setAnimation(
Animation * animation
);
// 创建特定帧间隔的帧动画
Animation(
double interval, /* 帧间隔(秒) */
const std::initializer_list<Image*>& vImages /* 关键帧列表 */
);
#else
// 创建帧动画
Animation(
int number, /* 帧数量 */
Image * frame, /* 第一帧 */
...
);
// 获取该动作的拷贝对象
virtual Animate * clone() const override;
// 创建特定帧间隔的帧动画
Animation(
double interval, /* 帧间隔(秒) */
int number, /* 帧数量 */
Image * frame, /* 第一帧 */
...
);
#endif
virtual ~Animation();
// 添加关键帧
void add(
Image * frame /* 关键帧 */
);
#ifdef HIGHER_THAN_VS2012
// 添加多个关键帧
void add(
const std::initializer_list<Image*>& vImages /* 关键帧列表 */
);
#else
// 添加多个关键帧
void add(
int number, /* 帧数量 */
Image * frame, /* 第一帧 */
...
);
#endif
// 设置每一帧的时间间隔
void setInterval(
double interval /* 帧间隔(秒) */
);
// 获取该动画的拷贝对象
virtual Animation * clone() const override;
// 获取该动画的倒转
virtual Animation * reverse() const override;
// 获取该动作的倒转
virtual Animate * reverse() const override;
// 重置动作
virtual void reset() override;
@ -687,9 +643,8 @@ protected:
virtual void _update() override;
protected:
double _interval;
UINT _frameIndex;
std::vector<Image*> _frames;
Animation * _animation;
};

View File

@ -712,6 +712,97 @@ protected:
};
// 帧动画
class Animation :
public Object
{
public:
// 创建帧动画
Animation();
// 创建特定间隔的帧动画
Animation(
double interval /* 帧间隔(秒) */
);
// 创建特定帧间隔的帧动画
Animation(
double interval, /* 帧间隔(秒) */
const std::vector<Image*>& frames /* 关键帧数组 */
);
// 创建帧动画
Animation(
int number, /* 帧数量 */
Image * frame, /* 第一帧 */
...
);
// 创建特定帧间隔的帧动画
Animation(
double interval, /* 帧间隔(秒) */
int number, /* 帧数量 */
Image * frame, /* 第一帧 */
...
);
#ifdef HIGHER_THAN_VS2012
// 创建帧动画
Animation(
const std::initializer_list<Image*>& frames /* 关键帧列表 */
);
// 创建特定帧间隔的帧动画
Animation(
double interval, /* 帧间隔(秒) */
const std::initializer_list<Image*>& frames /* 关键帧列表 */
);
#endif
virtual ~Animation();
// 添加关键帧
void add(
Image * frame /* 关键帧 */
);
// 添加多个关键帧
void add(
int number, /* 帧数量 */
Image * frame, /* 第一帧 */
...
);
#ifdef HIGHER_THAN_VS2012
// 添加多个关键帧
void add(
const std::initializer_list<Image*>& frames /* 关键帧列表 */
);
#endif
// 获取帧间隔
double getInterval() const;
// 获取关键帧
const std::vector<Image*>& getFrames() const;
// 设置每一帧的时间间隔
void setInterval(
double interval /* 帧间隔(秒) */
);
// 获取动画的拷贝对象
virtual Animation * clone() const;
// 销毁对象
virtual void onDestroy() override;
protected:
double _interval;
std::vector<Image*> _frames;
};
class Node;
class SceneManager;
class Transition;
@ -760,7 +851,7 @@ public:
#ifdef HIGHER_THAN_VS2012
// 添加多个节点到场景
virtual void add(
const std::initializer_list<Node*>& vNodes, /* 节点列表 */
const std::initializer_list<Node*>& nodes, /* 节点列表 */
int order = 0 /* 渲染顺序 */
);
#endif

View File

@ -49,13 +49,13 @@ public:
// 切换场景
static void enter(
Scene * scene, /* 下一个场景的指针 */
Transition * transition = nullptr, /* 场景切换动 */
Transition * transition = nullptr, /* 场景切换动 */
bool saveCurrentScene = true /* 是否保存当前场景 */
);
// 返回上一场景
static void back(
Transition * transition = nullptr /* 场景切换动 */
Transition * transition = nullptr /* 场景切换动 */
);
// 清空保存的所有场景
@ -67,7 +67,7 @@ public:
// 获取场景栈
static std::stack<Scene*> getSceneStack();
// 是否正在进行转场动
// 是否正在进行转场动
static bool isTransitioning();
private:
@ -133,7 +133,7 @@ public:
static std::vector<Action*> getAll();
private:
// 更新动状态
// 更新动状态
static void __update();
// 添加动作

View File

@ -338,10 +338,17 @@ public:
const String& collliderName
);
// 添加多个可碰撞节点的名称
virtual void addColliableName(
int number, /* 名称数量 */
String collliderName, /* 第一个名称 */
...
);
#ifdef HIGHER_THAN_VS2012
// 添加多个可碰撞节点的名称
virtual void addColliableName(
const std::initializer_list<String>& vCollliderName /* 名称列表 */
const std::initializer_list<String>& colliderNames /* 名称列表 */
);
#endif
@ -359,48 +366,48 @@ public:
#ifdef HIGHER_THAN_VS2012
// 添加多个子节点
virtual void addChild(
const std::initializer_list<Node*>& vNodes, /* 节点列表 */
const std::initializer_list<Node*>& nodes, /* 节点列表 */
int order = 0 /* 渲染顺序 */
);
#endif
// 执行动
// 执行动
virtual void runAction(
Action * action
);
// 继续动
// 继续动
virtual void resumeAction(
const String& strActionName
);
// 暂停动
// 暂停动
virtual void pauseAction(
const String& strActionName
);
// 停止动
// 停止动
virtual void stopAction(
const String& strActionName
);
// 获取名称相同的动
// 获取名称相同的动
virtual Action * getAction(
const String& strActionName
);
// 获取所有名称相同的动
// 获取所有名称相同的动
virtual std::vector<Action*> getActions(
const String& strActionName
);
// 继续所有暂停动
// 继续所有暂停动
virtual void resumeAllActions();
// 暂停所有动
// 暂停所有动
virtual void pauseAllActions();
// 停止所有动
// 停止所有动
virtual void stopAllActions();
// 修改节点的默认中心点位置
@ -958,18 +965,18 @@ public:
// 创建空菜单
Menu();
#ifdef HIGHER_THAN_VS2012
// 创建菜单
Menu(
const std::initializer_list<Button*>& vButtons /* 按钮列表 */
);
#else
// 创建菜单
Menu(
int number, /* 菜单中按钮的数量 */
Button * button1, /* 第一个按钮 */
...
);
#ifdef HIGHER_THAN_VS2012
// 创建菜单
Menu(
const std::initializer_list<Button*>& vButtons /* 按钮列表 */
);
#endif
// 获取菜单是否禁用

View File

@ -8,7 +8,7 @@ namespace e2d
class SceneManager;
// 基础过渡动
// 基础过渡动
class Transition :
public Object
{
@ -19,32 +19,32 @@ public:
virtual ~Transition();
// 场景切换动是否结束
// 场景切换动是否结束
bool isDone();
// Ïú»Ù¶ÔÏó
virtual void onDestroy() override;
protected:
// 初始化场景动
// 初始化场景动
virtual void _init(
Scene * prev,
Scene * next
);
// 更新场景动
// 更新场景动
virtual void _update();
// 更新场景动
// 更新场景动
virtual void _updateCustom() = 0;
// 渲染场景动
// 渲染场景动
virtual void _render();
// 重置场景动
// 重置场景动
virtual void _reset() = 0;
// 停止场景动
// 停止场景动
virtual void _stop();
protected:
@ -66,19 +66,19 @@ class TransitionFade :
public Transition
{
public:
// 创建淡入淡出式的场景切换动
// 创建淡入淡出式的场景切换动
TransitionFade(
double duration /* 动持续时长 */
double duration /* 动持续时长 */
);
// 创建淡入淡出式的场景切换动
// 创建淡入淡出式的场景切换动
TransitionFade(
double fadeOutDuration, /* 前一场景淡出动持续时长 */
double fadeInDuration /* 后一场景淡入动持续时长 */
double fadeOutDuration, /* 前一场景淡出动持续时长 */
double fadeInDuration /* 后一场景淡入动持续时长 */
);
protected:
// 更新动
// 更新动
virtual void _updateCustom() override;
virtual void _init(
@ -99,13 +99,13 @@ class TransitionEmerge :
public Transition
{
public:
// 创建浮现式的场景切换动
// 创建浮现式的场景切换动
TransitionEmerge(
double duration /* 浮现动持续时长 */
double duration /* 浮现动持续时长 */
);
protected:
// 更新动
// 更新动
virtual void _updateCustom() override;
virtual void _init(
@ -121,14 +121,14 @@ class TransitionMove :
public Transition
{
public:
// 创建移动式的场景切换动
// 创建移动式的场景切换动
TransitionMove(
double moveDuration, /* 场景移动动持续时长 */
double moveDuration, /* 场景移动动持续时长 */
Direction direction = Direction::LEFT /* ³¡¾°Òƶ¯·½Ïò */
);
protected:
// 更新动
// 更新动
virtual void _updateCustom() override;
virtual void _init(

View File

@ -200,7 +200,7 @@
<ClCompile Include="..\..\core\Action\CallFunc.cpp" />
<ClCompile Include="..\..\core\Action\Delay.cpp" />
<ClCompile Include="..\..\core\Action\MoveBy.cpp" />
<ClCompile Include="..\..\core\Action\Animation.cpp" />
<ClCompile Include="..\..\core\Action\Animate.cpp" />
<ClCompile Include="..\..\core\Action\MoveTo.cpp" />
<ClCompile Include="..\..\core\Action\Loop.cpp" />
<ClCompile Include="..\..\core\Action\OpacityBy.cpp" />
@ -221,6 +221,7 @@
<ClCompile Include="..\..\core\Collider\ColliderCircle.cpp" />
<ClCompile Include="..\..\core\Collider\ColliderEllipse.cpp" />
<ClCompile Include="..\..\core\Collider\ColliderRect.cpp" />
<ClCompile Include="..\..\core\Common\Animation.cpp" />
<ClCompile Include="..\..\core\Common\Color.cpp" />
<ClCompile Include="..\..\core\Common\Function.cpp" />
<ClCompile Include="..\..\core\Common\TextStyle.cpp" />

View File

@ -39,9 +39,6 @@
<ClCompile Include="..\..\core\Action\ActionGradual.cpp">
<Filter>Action</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Action\Animation.cpp">
<Filter>Action</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Common\Image.cpp">
<Filter>Common</Filter>
</ClCompile>
@ -213,6 +210,12 @@
<ClCompile Include="..\..\core\Transition\Transition.cpp">
<Filter>Transition</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Action\Animate.cpp">
<Filter>Action</Filter>
</ClCompile>
<ClCompile Include="..\..\core\Common\Animation.cpp">
<Filter>Common</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\core\easy2d.h" />