diff --git a/core/Action/ActionGradual.cpp b/core/Action/ActionGradual.cpp index 8d159805..872ebede 100644 --- a/core/Action/ActionGradual.cpp +++ b/core/Action/ActionGradual.cpp @@ -21,7 +21,7 @@ void e2d::ActionGradual::_update() this->stop(); return; } - // 计算动画进度 + // 计算动作进度 _delta = min((Time::getTotalTime() - _last) / _duration, 1); // 判断动作是否结束 if (_delta >= 1) diff --git a/core/Action/Animate.cpp b/core/Action/Animate.cpp new file mode 100644 index 00000000..1de48a19 --- /dev/null +++ b/core/Action/Animate.cpp @@ -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(_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(_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 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); +} diff --git a/core/Action/Animation.cpp b/core/Action/Animation.cpp deleted file mode 100644 index 7b198ad6..00000000 --- a/core/Action/Animation.cpp +++ /dev/null @@ -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& vImages) - : _frameIndex(0) - , _interval(1) -{ - this->add(vImages); -} - -e2d::Animation::Animation(double interval, const std::initializer_list& 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(_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& 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; -} diff --git a/core/Action/MoveBy.cpp b/core/Action/MoveBy.cpp index 2286bf60..003d8667 100644 --- a/core/Action/MoveBy.cpp +++ b/core/Action/MoveBy.cpp @@ -10,6 +10,7 @@ e2d::MoveBy::MoveBy(double duration, Vector vector) : void e2d::MoveBy::_init() { ActionGradual::_init(); + if (_target) { _startPos = _target->getPos(); @@ -20,13 +21,10 @@ void e2d::MoveBy::_update() { ActionGradual::_update(); - if (_target == nullptr) + if (_target) { - this->stop(); - return; + _target->setPos(_startPos + _deltaPos * _delta); } - - _target->setPos(_startPos + _deltaPos * _delta); } e2d::MoveBy * e2d::MoveBy::clone() const diff --git a/core/Action/OpacityBy.cpp b/core/Action/OpacityBy.cpp index b51bbf23..d633f0d7 100644 --- a/core/Action/OpacityBy.cpp +++ b/core/Action/OpacityBy.cpp @@ -10,6 +10,7 @@ e2d::OpacityBy::OpacityBy(double duration, double opacity) : void e2d::OpacityBy::_init() { ActionGradual::_init(); + if (_target) { _startVal = _target->getOpacity(); @@ -20,13 +21,10 @@ void e2d::OpacityBy::_update() { ActionGradual::_update(); - if (_target == nullptr) + if (_target) { - this->stop(); - return; + _target->setOpacity(_startVal + _deltaVal * _delta); } - - _target->setOpacity(_startVal + _deltaVal * _delta); } e2d::OpacityBy * e2d::OpacityBy::clone() const diff --git a/core/Action/RotateBy.cpp b/core/Action/RotateBy.cpp index 52899a6a..c40f0e8c 100644 --- a/core/Action/RotateBy.cpp +++ b/core/Action/RotateBy.cpp @@ -10,6 +10,7 @@ e2d::RotateBy::RotateBy(double duration, double rotation) : void e2d::RotateBy::_init() { ActionGradual::_init(); + if (_target) { _startVal = _target->getRotation(); @@ -20,13 +21,10 @@ void e2d::RotateBy::_update() { ActionGradual::_update(); - if (_target == nullptr) + if (_target) { - this->stop(); - return; + _target->setRotation(_startVal + _deltaVal * _delta); } - - _target->setRotation(_startVal + _deltaVal * _delta); } e2d::RotateBy * e2d::RotateBy::clone() const diff --git a/core/Action/ScaleBy.cpp b/core/Action/ScaleBy.cpp index 193425df..fe703372 100644 --- a/core/Action/ScaleBy.cpp +++ b/core/Action/ScaleBy.cpp @@ -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,13 +30,10 @@ void e2d::ScaleBy::_update() { ActionGradual::_update(); - if (_target == nullptr) + if (_target) { - this->stop(); - return; + _target->setScale(_startScaleX + _deltaX * _delta, _startScaleY + _deltaY * _delta); } - - _target->setScale(_startScaleX + _deltaX * _delta, _startScaleY + _deltaY * _delta); } e2d::ScaleBy * e2d::ScaleBy::clone() const diff --git a/core/Action/Sequence.cpp b/core/Action/Sequence.cpp index 0f194bfd..f677b63c 100644 --- a/core/Action/Sequence.cpp +++ b/core/Action/Sequence.cpp @@ -5,25 +5,26 @@ e2d::Sequence::Sequence() { } -#ifdef HIGHER_THAN_VS2012 -e2d::Sequence::Sequence(const std::initializer_list& 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& 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& 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& actions) +{ + for (const auto &action : actions) + { + this->add(action); } } #endif diff --git a/core/Action/Spawn.cpp b/core/Action/Spawn.cpp index 7407fc11..5c888d9e 100644 --- a/core/Action/Spawn.cpp +++ b/core/Action/Spawn.cpp @@ -4,24 +4,24 @@ e2d::Spawn::Spawn() { } -#ifdef HIGHER_THAN_VS2012 -e2d::Spawn::Spawn(const std::initializer_list& 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& 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& 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& actions) +{ + for (const auto &action : actions) + { + this->add(action); } } #endif diff --git a/core/Base/Game.cpp b/core/Base/Game.cpp index facefb8d..f40ab756 100644 --- a/core/Base/Game.cpp +++ b/core/Base/Game.cpp @@ -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(); diff --git a/core/Common/Animation.cpp b/core/Common/Animation.cpp new file mode 100644 index 00000000..96c3733a --- /dev/null +++ b/core/Common/Animation.cpp @@ -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& 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& frames) + : _interval(1) +{ + this->add(frames); +} + +e2d::Animation::Animation(double interval, const std::initializer_list& 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& frames) +{ + for (const auto &image : frames) + { + this->add(image); + } +} +#endif + +double e2d::Animation::getInterval() const +{ + return _interval; +} + +const std::vector& 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; +} diff --git a/core/Common/Image.cpp b/core/Common/Image.cpp index 9bae2b60..8f00af26 100644 --- a/core/Common/Image.cpp +++ b/core/Common/Image.cpp @@ -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 名 diff --git a/core/Common/Scene.cpp b/core/Common/Scene.cpp index 8057f332..98d55127 100644 --- a/core/Common/Scene.cpp +++ b/core/Common/Scene.cpp @@ -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& vNodes, int order) +void e2d::Scene::add(const std::initializer_list& nodes, int order) { - for (const auto &node : vNodes) + for (const auto &node : nodes) { this->add(node, order); } diff --git a/core/Manager/ActionManager.cpp b/core/Manager/ActionManager.cpp index 8fc531f2..122ee842 100644 --- a/core/Manager/ActionManager.cpp +++ b/core/Manager/ActionManager.cpp @@ -213,15 +213,15 @@ void e2d::ActionManager::stopAll() std::vector e2d::ActionManager::get(const String& strActionName) { - std::vector vActions; + std::vector 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::ActionManager::getAll() diff --git a/core/Manager/SceneManager.cpp b/core/Manager/SceneManager.cpp index a5b5fead..b299997e 100644 --- a/core/Manager/SceneManager.cpp +++ b/core/Manager/SceneManager.cpp @@ -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()) diff --git a/core/Node/Menu.cpp b/core/Node/Menu.cpp index 12601484..1bfebb63 100644 --- a/core/Node/Menu.cpp +++ b/core/Node/Menu.cpp @@ -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& vButtons) : _enable(true) @@ -14,21 +29,6 @@ e2d::Menu::Menu(const std::initializer_list& 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 diff --git a/core/Node/Node.cpp b/core/Node/Node.cpp index bbb04b6d..79834302 100644 --- a/core/Node/Node.cpp +++ b/core/Node/Node.cpp @@ -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& 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& 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& vNodes, int order) +void e2d::Node::addChild(const std::initializer_list& nodes, int order) { - for (const auto &node : vNodes) + for (const auto &node : nodes) { this->addChild(node, order); } diff --git a/core/Transition/Transition.cpp b/core/Transition/Transition.cpp index 3d668ef3..8b68ac94 100644 --- a/core/Transition/Transition.cpp +++ b/core/Transition/Transition.cpp @@ -60,7 +60,7 @@ void e2d::Transition::_init(Scene * prev, Scene * next) void e2d::Transition::_update() { - // 计算动画进度 + // 计算动作进度 if (_duration == 0) { _delta = 1; diff --git a/core/e2daction.h b/core/e2daction.h index 3613e2e5..d6bc1019 100644 --- a/core/e2daction.h +++ b/core/e2daction.h @@ -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,17 +467,17 @@ public: // 创建顺序动作 Sequence(); + // 创建顺序动作 + Sequence( + int number, /* 动作数量 */ + Action * action, /* 第一个动作 */ + ... + ); + #ifdef HIGHER_THAN_VS2012 // 创建顺序动作 Sequence( - const std::initializer_list& vActions /* 动作列表 */ - ); -#else - // 创建顺序动作 - Sequence( - int number, /* 动作数量 */ - Action * action, /* 第一个动作 */ - ... + const std::initializer_list& actions /* 动作列表 */ ); #endif @@ -488,18 +488,18 @@ public: Action * action ); -#ifdef HIGHER_THAN_VS2012 - // 在结尾添加多个动作 - void add( - const std::initializer_list& vActions /* 动作列表 */ - ); -#else // 在结尾添加多个动作 void add( int number, /* 动作数量 */ Action * action, /* 第一个动作 */ ... ); + +#ifdef HIGHER_THAN_VS2012 + // 在结尾添加多个动作 + void add( + const std::initializer_list& 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& vActions /* 动作列表 */ - ); -#else // 创建同步动作 Spawn( int number, /* 动作数量 */ Action * action, /* 第一个动作 */ ... ); + +#ifdef HIGHER_THAN_VS2012 + // 创建同步动作 + Spawn( + const std::initializer_list& actions /* 动作列表 */ + ); #endif virtual ~Spawn(); @@ -559,18 +559,18 @@ public: Action * action ); -#ifdef HIGHER_THAN_VS2012 - // 在结尾添加多个动作 - void add( - const std::initializer_list& vActions /* 动作列表 */ - ); -#else // 在结尾添加多个动作 void add( int number, /* 动作数量 */ Action * action, /* 第一个动作 */ ... ); + +#ifdef HIGHER_THAN_VS2012 + // 在结尾添加多个动作 + void add( + const std::initializer_list& 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& vImages /* 关键帧列表 */ + virtual ~Animate(); + + // 获取动画 + virtual Animation * getAnimation() const; + + // 设置动画 + virtual void setAnimation( + Animation * animation ); - // 创建特定帧间隔的帧动画 - Animation( - double interval, /* 帧间隔(秒) */ - const std::initializer_list& 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& 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 _frames; + UINT _frameIndex; + Animation * _animation; }; diff --git a/core/e2dcommon.h b/core/e2dcommon.h index 8cc04ce3..e89e4aef 100644 --- a/core/e2dcommon.h +++ b/core/e2dcommon.h @@ -712,6 +712,97 @@ protected: }; +// 帧动画 +class Animation : + public Object +{ +public: + // 创建帧动画 + Animation(); + + // 创建特定间隔的帧动画 + Animation( + double interval /* 帧间隔(秒) */ + ); + + // 创建特定帧间隔的帧动画 + Animation( + double interval, /* 帧间隔(秒) */ + const std::vector& frames /* 关键帧数组 */ + ); + + // 创建帧动画 + Animation( + int number, /* 帧数量 */ + Image * frame, /* 第一帧 */ + ... + ); + + // 创建特定帧间隔的帧动画 + Animation( + double interval, /* 帧间隔(秒) */ + int number, /* 帧数量 */ + Image * frame, /* 第一帧 */ + ... + ); + +#ifdef HIGHER_THAN_VS2012 + // 创建帧动画 + Animation( + const std::initializer_list& frames /* 关键帧列表 */ + ); + + // 创建特定帧间隔的帧动画 + Animation( + double interval, /* 帧间隔(秒) */ + const std::initializer_list& frames /* 关键帧列表 */ + ); +#endif + + virtual ~Animation(); + + // 添加关键帧 + void add( + Image * frame /* 关键帧 */ + ); + + // 添加多个关键帧 + void add( + int number, /* 帧数量 */ + Image * frame, /* 第一帧 */ + ... + ); + +#ifdef HIGHER_THAN_VS2012 + // 添加多个关键帧 + void add( + const std::initializer_list& frames /* 关键帧列表 */ + ); +#endif + + // 获取帧间隔 + double getInterval() const; + + // 获取关键帧 + const std::vector& getFrames() const; + + // 设置每一帧的时间间隔 + void setInterval( + double interval /* 帧间隔(秒) */ + ); + + // 获取动画的拷贝对象 + virtual Animation * clone() const; + + // 销毁对象 + virtual void onDestroy() override; + +protected: + double _interval; + std::vector _frames; +}; + + class Node; class SceneManager; class Transition; @@ -760,7 +851,7 @@ public: #ifdef HIGHER_THAN_VS2012 // 添加多个节点到场景 virtual void add( - const std::initializer_list& vNodes, /* 节点列表 */ + const std::initializer_list& nodes, /* 节点列表 */ int order = 0 /* 渲染顺序 */ ); #endif diff --git a/core/e2dmanager.h b/core/e2dmanager.h index 9430bb96..911829c0 100644 --- a/core/e2dmanager.h +++ b/core/e2dmanager.h @@ -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 getSceneStack(); - // 是否正在进行转场动画 + // 是否正在进行转场动作 static bool isTransitioning(); private: @@ -133,7 +133,7 @@ public: static std::vector getAll(); private: - // 更新动画状态 + // 更新动作状态 static void __update(); // 添加动作 diff --git a/core/e2dnode.h b/core/e2dnode.h index 2e75341d..4088ad85 100644 --- a/core/e2dnode.h +++ b/core/e2dnode.h @@ -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& vCollliderName /* 名称列表 */ + const std::initializer_list& colliderNames /* 名称列表 */ ); #endif @@ -359,48 +366,48 @@ public: #ifdef HIGHER_THAN_VS2012 // 添加多个子节点 virtual void addChild( - const std::initializer_list& vNodes, /* 节点列表 */ + const std::initializer_list& 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 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& vButtons /* 按钮列表 */ - ); -#else // 创建菜单 Menu( int number, /* 菜单中按钮的数量 */ Button * button1, /* 第一个按钮 */ ... ); + +#ifdef HIGHER_THAN_VS2012 + // 创建菜单 + Menu( + const std::initializer_list& vButtons /* 按钮列表 */ + ); #endif // 获取菜单是否禁用 diff --git a/core/e2dtransition.h b/core/e2dtransition.h index 8597d2c1..79654e99 100644 --- a/core/e2dtransition.h +++ b/core/e2dtransition.h @@ -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( diff --git a/project/vs2017/Easy2D.vcxproj b/project/vs2017/Easy2D.vcxproj index b790094a..53fd96a5 100644 --- a/project/vs2017/Easy2D.vcxproj +++ b/project/vs2017/Easy2D.vcxproj @@ -200,7 +200,7 @@ - + @@ -221,6 +221,7 @@ + diff --git a/project/vs2017/Easy2D.vcxproj.filters b/project/vs2017/Easy2D.vcxproj.filters index b422979e..6469e08a 100644 --- a/project/vs2017/Easy2D.vcxproj.filters +++ b/project/vs2017/Easy2D.vcxproj.filters @@ -39,9 +39,6 @@ Action - - Action - Common @@ -213,6 +210,12 @@ Transition + + Action + + + Common +