diff --git a/project/vs2013/Easy2D.vcxproj b/project/vs2013/Easy2D.vcxproj
index eeb88e11..3b5933ed 100644
--- a/project/vs2013/Easy2D.vcxproj
+++ b/project/vs2013/Easy2D.vcxproj
@@ -20,7 +20,8 @@
-
+
+
@@ -88,7 +89,7 @@
-
+
diff --git a/project/vs2013/Easy2D.vcxproj.filters b/project/vs2013/Easy2D.vcxproj.filters
index 39446fc8..2a5164c8 100644
--- a/project/vs2013/Easy2D.vcxproj.filters
+++ b/project/vs2013/Easy2D.vcxproj.filters
@@ -2,9 +2,6 @@
-
- core
-
core
@@ -200,6 +197,12 @@
core
+
+ core
+
+
+ core
+
@@ -216,9 +219,6 @@
-
- core
-
core
@@ -348,5 +348,8 @@
core
+
+ core
+
\ No newline at end of file
diff --git a/project/vs2015/Easy2D.vcxproj b/project/vs2015/Easy2D.vcxproj
index 3e35a3fd..707919bb 100644
--- a/project/vs2015/Easy2D.vcxproj
+++ b/project/vs2015/Easy2D.vcxproj
@@ -20,7 +20,8 @@
-
+
+
@@ -88,7 +89,7 @@
-
+
diff --git a/project/vs2015/Easy2D.vcxproj.filters b/project/vs2015/Easy2D.vcxproj.filters
index 39446fc8..2a5164c8 100644
--- a/project/vs2015/Easy2D.vcxproj.filters
+++ b/project/vs2015/Easy2D.vcxproj.filters
@@ -2,9 +2,6 @@
-
- core
-
core
@@ -200,6 +197,12 @@
core
+
+ core
+
+
+ core
+
@@ -216,9 +219,6 @@
-
- core
-
core
@@ -348,5 +348,8 @@
core
+
+ core
+
\ No newline at end of file
diff --git a/project/vs2017/Easy2D.vcxproj b/project/vs2017/Easy2D.vcxproj
index ae5126c0..78bd6f34 100644
--- a/project/vs2017/Easy2D.vcxproj
+++ b/project/vs2017/Easy2D.vcxproj
@@ -20,7 +20,8 @@
-
+
+
@@ -88,7 +89,7 @@
-
+
diff --git a/project/vs2017/Easy2D.vcxproj.filters b/project/vs2017/Easy2D.vcxproj.filters
index 39446fc8..2a5164c8 100644
--- a/project/vs2017/Easy2D.vcxproj.filters
+++ b/project/vs2017/Easy2D.vcxproj.filters
@@ -2,9 +2,6 @@
-
- core
-
core
@@ -200,6 +197,12 @@
core
+
+ core
+
+
+ core
+
@@ -216,9 +219,6 @@
-
- core
-
core
@@ -348,5 +348,8 @@
core
+
+ core
+
\ No newline at end of file
diff --git a/src/core/Action.hpp b/src/core/Action.hpp
index e73d1e5b..12c68558 100644
--- a/src/core/Action.hpp
+++ b/src/core/Action.hpp
@@ -43,17 +43,14 @@ namespace easy2d
virtual ~Action() {}
- // 获取动作运行状态
- virtual bool IsRunning() { return running_; }
-
// 继续动作
- virtual void Resume() { running_ = true; }
+ void Resume() { running_ = true; }
// 暂停动作
- virtual void Pause() { running_ = false; }
+ void Pause() { running_ = false; }
// 停止动作
- virtual void Stop() { if (!done_) { done_ = true; if (cb_) cb_(); } }
+ void Stop() { if (!done_) { done_ = true; if (cb_) cb_(); } }
// 获取动作的拷贝
virtual ActionPtr Clone() const = 0;
@@ -61,6 +58,9 @@ namespace easy2d
// 获取动作的倒转
virtual ActionPtr Reverse() const = 0;
+ // 设置动作结束时的回调函数
+ void SetCallback(std::function cb) { cb_ = cb; }
+
// 重置动作
virtual void Reset()
{
@@ -68,13 +68,12 @@ namespace easy2d
done_ = false;
}
- // 设置动作结束时的回调函数
- void SetCallback(std::function cb) { cb_ = cb; }
-
virtual bool IsDone() const { return done_; }
+ virtual bool IsRunning() { return running_; }
+
protected:
- virtual void Start()
+ void Start()
{
running_ = true;
this->Reset();
@@ -82,7 +81,7 @@ namespace easy2d
virtual void Init(Node* target) { initialized_ = true; }
- virtual void Update(Node* target, Duration const& dt)
+ virtual void Update(Node* target, Duration dt)
{
if (!initialized_)
{
diff --git a/src/core/ActionCombined.cpp b/src/core/ActionGroup.cpp
similarity index 96%
rename from src/core/ActionCombined.cpp
rename to src/core/ActionGroup.cpp
index 8a3d201e..e9dbd3b8 100644
--- a/src/core/ActionCombined.cpp
+++ b/src/core/ActionGroup.cpp
@@ -18,7 +18,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
-#include "ActionCombined.h"
+#include "ActionGroup.h"
#include "logs.h"
namespace easy2d
@@ -75,7 +75,7 @@ namespace easy2d
}
}
- void Loop::Update(Node* target, Duration const& dt)
+ void Loop::Update(Node* target, Duration dt)
{
Action::Update(target, dt);
@@ -141,7 +141,7 @@ namespace easy2d
actions_[0]->Init(target);
}
- void Sequence::Update(Node* target, Duration const& dt)
+ void Sequence::Update(Node* target, Duration dt)
{
Action::Update(target, dt);
@@ -249,7 +249,7 @@ namespace easy2d
}
}
- void Spawn::Update(Node* target, Duration const& dt)
+ void Spawn::Update(Node* target, Duration dt)
{
Action::Update(target, dt);
diff --git a/src/core/ActionCombined.h b/src/core/ActionGroup.h
similarity index 93%
rename from src/core/ActionCombined.h
rename to src/core/ActionGroup.h
index eb4a94a2..3d097859 100644
--- a/src/core/ActionCombined.h
+++ b/src/core/ActionGroup.h
@@ -51,7 +51,7 @@ namespace easy2d
virtual void Init(Node* target) override;
// 更新动作
- virtual void Update(Node* target, Duration const& dt) override;
+ virtual void Update(Node* target, Duration dt) override;
protected:
ActionPtr action_;
@@ -97,7 +97,7 @@ namespace easy2d
virtual void Init(Node* target) override;
// 更新动作
- virtual void Update(Node* target, Duration const& dt) override;
+ virtual void Update(Node* target, Duration dt) override;
protected:
UINT action_index_;
@@ -142,7 +142,7 @@ namespace easy2d
virtual void Init(Node* target) override;
// 更新动作
- virtual void Update(Node* target, Duration const& dt) override;
+ virtual void Update(Node* target, Duration dt) override;
protected:
Array actions_;
diff --git a/src/core/ActionHelper.h b/src/core/ActionHelper.h
new file mode 100644
index 00000000..9aa26df3
--- /dev/null
+++ b/src/core/ActionHelper.h
@@ -0,0 +1,191 @@
+// Copyright (c) 2016-2018 Easy2D - Nomango
+//
+// Permission is hereby granted, free of charge, to any person obtaining a copy
+// of this software and associated documentation files (the "Software"), to deal
+// in the Software without restriction, including without limitation the rights
+// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+// copies of the Software, and to permit persons to whom the Software is
+// furnished to do so, subject to the following conditions:
+//
+// The above copyright notice and this permission notice shall be included in
+// all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+// THE SOFTWARE.
+
+#pragma once
+#include "ActionGroup.h"
+#include "ActionTween.h"
+#include "Delay.h"
+
+namespace easy2d
+{
+ struct ActionHelper
+ {
+ ActionHelper& SetLoopCount(int loop) { this->loop = loop; return (*this); }
+
+ ActionHelper(ActionPtr const& base) : base(base), loop(0) {}
+
+ operator ActionPtr() const
+ {
+ if (loop)
+ return ActionPtr(new (std::nothrow) Loop(base));
+ return base;
+ }
+
+ ActionPtr base;
+ int loop;
+ };
+
+ struct TweenActionHelper
+ {
+ TweenActionHelper& SetDuration(Duration dur) { this->dur = dur; return (*this); }
+
+ TweenActionHelper& SetLoopCount(int loop) { this->loop = loop; return (*this); }
+
+ TweenActionHelper& SetEaseFunc(EaseFunc ease) { this->ease = ease; return (*this); }
+
+ TweenActionHelper(ActionTweenPtr const& base) : base(base), dur(), loop(0), ease(EaseFunc::Linear) {}
+
+ operator ActionPtr() const
+ {
+ base->SetEaseFunction(ease);
+ base->SetDuration(dur);
+ if (loop)
+ return ActionPtr(new (std::nothrow) Loop(base));
+ return base;
+ }
+
+ ActionTweenPtr base;
+ Duration dur;
+ int loop;
+ EaseFunc ease;
+ };
+
+ struct Tween
+ {
+ public:
+ static inline TweenActionHelper
+ MoveBy(Point const& vector)
+ {
+ return TweenActionHelper(new easy2d::MoveBy(0, vector));
+ }
+
+ static inline TweenActionHelper
+ MoveTo(Point const& pos)
+ {
+ return TweenActionHelper(new easy2d::MoveTo(0, pos));
+ }
+
+ static inline TweenActionHelper
+ JumpBy(
+ Point const& pos, /* 目的坐标 */
+ float height, /* 跳跃高度 */
+ int jumps = 1) /* 跳跃次数 */
+ {
+ return TweenActionHelper(new easy2d::JumpBy(0, pos, height, jumps));
+ }
+
+ static inline TweenActionHelper
+ JumpTo(
+ Point const& pos, /* 目的坐标 */
+ float height, /* 跳跃高度 */
+ int jumps = 1) /* 跳跃次数 */
+ {
+ return TweenActionHelper(new easy2d::JumpTo(0, pos, height, jumps));
+ }
+
+ static inline TweenActionHelper
+ ScaleBy(float scale)
+ {
+ return TweenActionHelper(new easy2d::ScaleBy(0, scale));
+ }
+
+ static inline TweenActionHelper
+ ScaleBy(float scale_x, float scale_y)
+ {
+ return TweenActionHelper(new easy2d::ScaleBy(0, scale_x, scale_y));
+ }
+
+ static inline TweenActionHelper
+ ScaleTo(float scale)
+ {
+ return TweenActionHelper(new easy2d::ScaleTo(0, scale));
+ }
+
+ static inline TweenActionHelper
+ ScaleTo(float scale_x, float scale_y)
+ {
+ return TweenActionHelper(new easy2d::ScaleTo(0, scale_x, scale_y));
+ }
+
+ static inline TweenActionHelper
+ OpacityBy(float opacity)
+ {
+ return TweenActionHelper(new easy2d::OpacityBy(0, opacity));
+ }
+
+ static inline TweenActionHelper
+ OpacityTo(float opacity)
+ {
+ return TweenActionHelper(new easy2d::OpacityTo(0, opacity));
+ }
+
+ static inline TweenActionHelper
+ FadeIn(Duration dur)
+ {
+ return TweenActionHelper(new easy2d::FadeIn(dur));
+ }
+
+ static inline TweenActionHelper
+ FadeOut(Duration dur)
+ {
+ return TweenActionHelper(new easy2d::FadeOut(dur));
+ }
+
+ static inline TweenActionHelper
+ RotateBy(float rotation)
+ {
+ return TweenActionHelper(new easy2d::RotateBy(0, rotation));
+ }
+
+ static inline TweenActionHelper
+ RotateTo(float rotation)
+ {
+ return TweenActionHelper(new easy2d::RotateTo(0, rotation));
+ }
+
+ static inline TweenActionHelper
+ Path(
+ GeometryPtr const& geo, /* 几何图形 */
+ bool rotating = false, /* 沿路径切线方向旋转 */
+ float start = 0.f, /* 起点 */
+ float end = 1.f) /* 终点 */
+ {
+ return TweenActionHelper(new easy2d::PathAction(0, geo, rotating, start, end));
+ }
+
+ static inline ActionHelper
+ Delay(Duration dur)
+ {
+ return ActionHelper(new easy2d::Delay(dur));
+ }
+
+ static inline ActionHelper
+ Sequence(Array const& actions)
+ {
+ return ActionHelper(new easy2d::Sequence(actions));
+ }
+
+ static inline ActionHelper
+ Spawn(Array const& actions)
+ {
+ return ActionHelper(new easy2d::Spawn(actions));
+ }
+ };
+}
diff --git a/src/core/ActionManager.cpp b/src/core/ActionManager.cpp
index d4a0fe60..97dba9be 100644
--- a/src/core/ActionManager.cpp
+++ b/src/core/ActionManager.cpp
@@ -23,7 +23,7 @@
namespace easy2d
{
- void ActionManager::UpdateActions(Node* target, Duration const& dt)
+ void ActionManager::UpdateActions(Node* target, Duration dt)
{
if (actions_.IsEmpty())
return;
diff --git a/src/core/ActionManager.h b/src/core/ActionManager.h
index c46a2a86..3d2767e2 100644
--- a/src/core/ActionManager.h
+++ b/src/core/ActionManager.h
@@ -46,7 +46,7 @@ namespace easy2d
Actions const& GetAllActions() const;
protected:
- void UpdateActions(Node* target, Duration const& dt);
+ void UpdateActions(Node* target, Duration dt);
protected:
Actions actions_;
diff --git a/src/core/ActionTween.cpp b/src/core/ActionTween.cpp
index dd8ca3b6..8889e32b 100644
--- a/src/core/ActionTween.cpp
+++ b/src/core/ActionTween.cpp
@@ -27,10 +27,10 @@
namespace easy2d
{
//-------------------------------------------------------
- // Tween
+ // ActionTween
//-------------------------------------------------------
- Tween::Tween()
+ ActionTween::ActionTween()
: elapsed_()
, duration_()
, ease_func_(math::Linear)
@@ -38,7 +38,7 @@ namespace easy2d
{
}
- Tween::Tween(Duration const& duration, EaseFunc func)
+ ActionTween::ActionTween(Duration duration, EaseFunc func)
: elapsed_()
, ease_func_(math::Linear)
, ease_type_(EaseFunc::Linear)
@@ -47,7 +47,7 @@ namespace easy2d
SetEaseFunction(func);
}
- void Tween::SetEaseFunction(EaseFunc func)
+ void ActionTween::SetEaseFunction(EaseFunc func)
{
ease_type_ = func;
switch (func)
@@ -150,29 +150,29 @@ namespace easy2d
}
}
- void Tween::SetEaseFunction(EaseFunction func)
+ void ActionTween::SetEaseFunction(EaseFunction func)
{
ease_func_ = func;
ease_type_ = EaseFunc(-1);
}
- void Tween::Reset()
+ void ActionTween::Reset()
{
Action::Reset();
elapsed_ = Duration{};
}
- Duration const & Tween::GetDuration() const
+ Duration ActionTween::GetDuration() const
{
return duration_;
}
- void Tween::Init(Node* target)
+ void ActionTween::Init(Node* target)
{
Action::Init(target);
}
- void Tween::Update(Node* target, Duration const& dt)
+ void ActionTween::Update(Node* target, Duration dt)
{
Action::Update(target, dt);
@@ -195,7 +195,7 @@ namespace easy2d
UpdateStep(target, ease_func_(step));
}
- void Tween::SetDuration(Duration const & duration)
+ void ActionTween::SetDuration(Duration duration)
{
duration_ = duration;
}
@@ -205,15 +205,15 @@ namespace easy2d
// Move Action
//-------------------------------------------------------
- MoveBy::MoveBy(Duration const& duration, Point const& vector, EaseFunc func)
- : Tween(duration, func)
+ MoveBy::MoveBy(Duration duration, Point const& vector, EaseFunc func)
+ : ActionTween(duration, func)
{
delta_pos_ = vector;
}
void MoveBy::Init(Node* target)
{
- Tween::Init(target);
+ ActionTween::Init(target);
if (target)
{
@@ -245,7 +245,7 @@ namespace easy2d
return new (std::nothrow) MoveBy(duration_, -delta_pos_, ease_type_);
}
- MoveTo::MoveTo(Duration const& duration, Point const& pos, EaseFunc func)
+ MoveTo::MoveTo(Duration duration, Point const& pos, EaseFunc func)
: MoveBy(duration, Point(), func)
{
end_pos_ = pos;
@@ -267,8 +267,8 @@ namespace easy2d
// Jump Action
//-------------------------------------------------------
- JumpBy::JumpBy(Duration const& duration, Point const& vec, float height, int jumps, EaseFunc func)
- : Tween(duration, func)
+ JumpBy::JumpBy(Duration duration, Point const& vec, float height, int jumps, EaseFunc func)
+ : ActionTween(duration, func)
, delta_pos_(vec)
, height_(height)
, jumps_(jumps)
@@ -287,7 +287,7 @@ namespace easy2d
void JumpBy::Init(Node* target)
{
- Tween::Init(target);
+ ActionTween::Init(target);
if (target)
{
@@ -314,7 +314,7 @@ namespace easy2d
}
}
- JumpTo::JumpTo(Duration const& duration, Point const& pos, float height, int jumps, EaseFunc func)
+ JumpTo::JumpTo(Duration duration, Point const& pos, float height, int jumps, EaseFunc func)
: JumpBy(duration, Point(), height, jumps, func)
, end_pos_(pos)
{
@@ -336,15 +336,15 @@ namespace easy2d
// Scale Action
//-------------------------------------------------------
- ScaleBy::ScaleBy(Duration const& duration, float scale, EaseFunc func)
- : Tween(duration, func)
+ ScaleBy::ScaleBy(Duration duration, float scale, EaseFunc func)
+ : ActionTween(duration, func)
{
delta_x_ = scale;
delta_y_ = scale;
}
- ScaleBy::ScaleBy(Duration const& duration, float scale_x, float scale_y, EaseFunc func)
- : Tween(duration, func)
+ ScaleBy::ScaleBy(Duration duration, float scale_x, float scale_y, EaseFunc func)
+ : ActionTween(duration, func)
{
delta_x_ = scale_x;
delta_y_ = scale_y;
@@ -352,7 +352,7 @@ namespace easy2d
void ScaleBy::Init(Node* target)
{
- Tween::Init(target);
+ ActionTween::Init(target);
if (target)
{
@@ -379,14 +379,14 @@ namespace easy2d
return new (std::nothrow) ScaleBy(duration_, -delta_x_, -delta_y_, ease_type_);
}
- ScaleTo::ScaleTo(Duration const& duration, float scale, EaseFunc func)
+ ScaleTo::ScaleTo(Duration duration, float scale, EaseFunc func)
: ScaleBy(duration, 0, 0, func)
{
end_scale_x_ = scale;
end_scale_y_ = scale;
}
- ScaleTo::ScaleTo(Duration const& duration, float scale_x, float scale_y, EaseFunc func)
+ ScaleTo::ScaleTo(Duration duration, float scale_x, float scale_y, EaseFunc func)
: ScaleBy(duration, 0, 0, func)
{
end_scale_x_ = scale_x;
@@ -410,15 +410,15 @@ namespace easy2d
// Opacity Action
//-------------------------------------------------------
- OpacityBy::OpacityBy(Duration const& duration, float opacity, EaseFunc func)
- : Tween(duration, func)
+ OpacityBy::OpacityBy(Duration duration, float opacity, EaseFunc func)
+ : ActionTween(duration, func)
{
delta_val_ = opacity;
}
void OpacityBy::Init(Node* target)
{
- Tween::Init(target);
+ ActionTween::Init(target);
if (target)
{
@@ -444,7 +444,7 @@ namespace easy2d
return new (std::nothrow) OpacityBy(duration_, -delta_val_, ease_type_);
}
- OpacityTo::OpacityTo(Duration const& duration, float opacity, EaseFunc func)
+ OpacityTo::OpacityTo(Duration duration, float opacity, EaseFunc func)
: OpacityBy(duration, 0, func)
{
end_val_ = opacity;
@@ -461,12 +461,12 @@ namespace easy2d
delta_val_ = end_val_ - start_val_;
}
- FadeIn::FadeIn(Duration const& duration, EaseFunc func)
+ FadeIn::FadeIn(Duration duration, EaseFunc func)
: OpacityTo(duration, 1, func)
{
}
- FadeOut::FadeOut(Duration const& duration, EaseFunc func)
+ FadeOut::FadeOut(Duration duration, EaseFunc func)
: OpacityTo(duration, 0, func)
{
}
@@ -476,15 +476,15 @@ namespace easy2d
// Rotate Action
//-------------------------------------------------------
- RotateBy::RotateBy(Duration const& duration, float rotation, EaseFunc func)
- : Tween(duration, func)
+ RotateBy::RotateBy(Duration duration, float rotation, EaseFunc func)
+ : ActionTween(duration, func)
, delta_val_(rotation)
{
}
void RotateBy::Init(Node* target)
{
- Tween::Init(target);
+ ActionTween::Init(target);
if (target)
{
@@ -510,7 +510,7 @@ namespace easy2d
return new (std::nothrow) RotateBy(duration_, -delta_val_, ease_type_);
}
- RotateTo::RotateTo(Duration const& duration, float rotation, EaseFunc func)
+ RotateTo::RotateTo(Duration duration, float rotation, EaseFunc func)
: RotateBy(duration, 0, func)
{
end_val_ = rotation;
@@ -532,8 +532,8 @@ namespace easy2d
// PathAction
//-------------------------------------------------------
- PathAction::PathAction(Duration const & duration, GeometryPtr const& geo, bool rotating, float start, float end, EaseFunc func)
- : Tween(duration, func)
+ PathAction::PathAction(Duration duration, GeometryPtr const& geo, bool rotating, float start, float end, EaseFunc func)
+ : ActionTween(duration, func)
, start_(start)
, end_(end)
, geo_(geo)
@@ -553,7 +553,7 @@ namespace easy2d
void PathAction::Init(Node * target)
{
- Tween::Init(target);
+ ActionTween::Init(target);
if (target)
{
diff --git a/src/core/ActionTween.h b/src/core/ActionTween.h
index 4ee34629..e910c553 100644
--- a/src/core/ActionTween.h
+++ b/src/core/ActionTween.h
@@ -74,14 +74,14 @@ namespace easy2d
// 补间动画
- class Tween
+ class ActionTween
: public Action
{
public:
- Tween();
+ ActionTween();
- explicit Tween(
- Duration const& duration,
+ explicit ActionTween(
+ Duration duration,
EaseFunc func
);
@@ -97,14 +97,14 @@ namespace easy2d
virtual void Reset() override;
- Duration const& GetDuration() const;
+ Duration GetDuration() const;
- void SetDuration(Duration const& duration);
+ void SetDuration(Duration duration);
protected:
virtual void Init(Node* target) override;
- virtual void Update(Node* target, Duration const& dt) override;
+ virtual void Update(Node* target, Duration dt) override;
virtual void UpdateStep(Node* target, float step) = 0;
@@ -118,11 +118,11 @@ namespace easy2d
// 相对位移动作
class MoveBy
- : public Tween
+ : public ActionTween
{
public:
explicit MoveBy(
- Duration const& duration, /* 持续时长 */
+ Duration duration, /* 持续时长 */
Point const& vector, /* 移动距离 */
EaseFunc func = EaseFunc::Linear /* 速度变化 */
);
@@ -151,7 +151,7 @@ namespace easy2d
{
public:
explicit MoveTo(
- Duration const& duration, /* 持续时长 */
+ Duration duration, /* 持续时长 */
Point const& pos, /* 目的坐标 */
EaseFunc func = EaseFunc::Linear /* 速度变化 */
);
@@ -176,11 +176,11 @@ namespace easy2d
// 相对跳跃动作
class JumpBy
- : public Tween
+ : public ActionTween
{
public:
explicit JumpBy(
- Duration const& duration, /* 持续时长 */
+ Duration duration, /* 持续时长 */
Point const& vec, /* 跳跃距离 */
float height, /* 跳跃高度 */
int jumps = 1, /* 跳跃次数 */
@@ -213,7 +213,7 @@ namespace easy2d
{
public:
explicit JumpTo(
- Duration const& duration, /* 持续时长 */
+ Duration duration, /* 持续时长 */
Point const& pos, /* 目的坐标 */
float height, /* 跳跃高度 */
int jumps = 1, /* 跳跃次数 */
@@ -240,17 +240,17 @@ namespace easy2d
// 相对缩放动作
class ScaleBy
- : public Tween
+ : public ActionTween
{
public:
explicit ScaleBy(
- Duration const& duration, /* 持续时长 */
+ Duration duration, /* 持续时长 */
float scale, /* 相对变化值 */
EaseFunc func = EaseFunc::Linear /* 速度变化 */
);
explicit ScaleBy(
- Duration const& duration, /* 持续时长 */
+ Duration duration, /* 持续时长 */
float scale_x, /* 横向缩放相对变化值 */
float scale_y, /* 纵向缩放相对变化值 */
EaseFunc func = EaseFunc::Linear /* 速度变化 */
@@ -281,13 +281,13 @@ namespace easy2d
{
public:
explicit ScaleTo(
- Duration const& duration, /* 持续时长 */
+ Duration duration, /* 持续时长 */
float scale, /* 目标值 */
EaseFunc func = EaseFunc::Linear /* 速度变化 */
);
explicit ScaleTo(
- Duration const& duration, /* 持续时长 */
+ Duration duration, /* 持续时长 */
float scale_x, /* 横向缩放目标值 */
float scale_y, /* 纵向缩放目标值 */
EaseFunc func = EaseFunc::Linear /* 速度变化 */
@@ -314,11 +314,11 @@ namespace easy2d
// 透明度相对渐变动作
class OpacityBy
- : public Tween
+ : public ActionTween
{
public:
explicit OpacityBy(
- Duration const& duration, /* 持续时长 */
+ Duration duration, /* 持续时长 */
float opacity, /* 相对变化值 */
EaseFunc func = EaseFunc::Linear /* 速度变化 */
);
@@ -346,7 +346,7 @@ namespace easy2d
{
public:
explicit OpacityTo(
- Duration const& duration, /* 持续时长 */
+ Duration duration, /* 持续时长 */
float opacity, /* 目标值 */
EaseFunc func = EaseFunc::Linear /* 速度变化 */
);
@@ -376,7 +376,7 @@ namespace easy2d
public:
// 创建淡入动作
explicit FadeIn(
- Duration const& duration, /* 持续时长 */
+ Duration duration, /* 持续时长 */
EaseFunc func = EaseFunc::Linear /* 速度变化 */
);
};
@@ -389,7 +389,7 @@ namespace easy2d
public:
// 创建淡出动作
explicit FadeOut(
- Duration const& duration, /* 持续时长 */
+ Duration duration, /* 持续时长 */
EaseFunc func = EaseFunc::Linear /* 速度变化 */
);
};
@@ -397,11 +397,11 @@ namespace easy2d
// 相对旋转动作
class RotateBy
- : public Tween
+ : public ActionTween
{
public:
explicit RotateBy(
- Duration const& duration, /* 持续时长 */
+ Duration duration, /* 持续时长 */
float rotation, /* 相对变化值 */
EaseFunc func = EaseFunc::Linear /* 速度变化 */
);
@@ -429,7 +429,7 @@ namespace easy2d
{
public:
explicit RotateTo(
- Duration const& duration, /* 持续时长 */
+ Duration duration, /* 持续时长 */
float rotation, /* 目标值 */
EaseFunc func = EaseFunc::Linear /* 速度变化 */
);
@@ -454,11 +454,11 @@ namespace easy2d
// 路径动作
class PathAction
- : public Tween
+ : public ActionTween
{
public:
explicit PathAction(
- Duration const& duration, /* 持续时长 */
+ Duration duration, /* 持续时长 */
GeometryPtr const& geo, /* 几何图形 */
bool rotating = false, /* 沿路径切线方向旋转 */
float start = 0.f, /* 起点 */
diff --git a/src/core/Animation.cpp b/src/core/Animation.cpp
index 2223c633..d514c84f 100644
--- a/src/core/Animation.cpp
+++ b/src/core/Animation.cpp
@@ -68,7 +68,7 @@ namespace easy2d
}
}
- void Animation::Update(Node* target, Duration const& dt)
+ void Animation::Update(Node* target, Duration dt)
{
Action::Update(target, dt);
diff --git a/src/core/Animation.h b/src/core/Animation.h
index a60afcfd..0d5b8a66 100644
--- a/src/core/Animation.h
+++ b/src/core/Animation.h
@@ -58,7 +58,7 @@ namespace easy2d
virtual void Init(Node* target) override;
// 更新动作
- virtual void Update(Node* target, Duration const& dt) override;
+ virtual void Update(Node* target, Duration dt) override;
protected:
size_t frame_index_;
diff --git a/src/core/DebugNode.cpp b/src/core/DebugNode.cpp
index d621c250..dc49f46d 100644
--- a/src/core/DebugNode.cpp
+++ b/src/core/DebugNode.cpp
@@ -82,7 +82,7 @@ namespace easy2d
);
}
- void DebugNode::OnUpdate(Duration const & dt)
+ void DebugNode::OnUpdate(Duration dt)
{
try
{
diff --git a/src/core/DebugNode.h b/src/core/DebugNode.h
index a868aedb..34e92a14 100644
--- a/src/core/DebugNode.h
+++ b/src/core/DebugNode.h
@@ -42,7 +42,7 @@ namespace easy2d
void OnRender() override;
- void OnUpdate(Duration const& dt) override;
+ void OnUpdate(Duration dt) override;
protected:
TextPtr debug_text_;
diff --git a/src/core/Delay.cpp b/src/core/Delay.cpp
index 06393cc6..4f3f3143 100644
--- a/src/core/Delay.cpp
+++ b/src/core/Delay.cpp
@@ -22,7 +22,7 @@
namespace easy2d
{
- Delay::Delay(Duration const& duration)
+ Delay::Delay(Duration duration)
: delta_()
, delay_(duration)
{
@@ -39,7 +39,7 @@ namespace easy2d
Action::Init(target);
}
- void Delay::Update(Node* target, Duration const& dt)
+ void Delay::Update(Node* target, Duration dt)
{
Action::Update(target, dt);
diff --git a/src/core/Delay.h b/src/core/Delay.h
index 8cb8ed7c..dbe3bf80 100644
--- a/src/core/Delay.h
+++ b/src/core/Delay.h
@@ -29,7 +29,7 @@ namespace easy2d
{
public:
explicit Delay(
- Duration const& duration /* 延迟时长(秒) */
+ Duration duration /* 延迟时长(秒) */
);
// 获取该动作的拷贝对象
@@ -44,7 +44,7 @@ namespace easy2d
protected:
virtual void Init(Node* target) override;
- virtual void Update(Node* target, Duration const& dt) override;
+ virtual void Update(Node* target, Duration dt) override;
protected:
Duration delay_;
diff --git a/src/core/Frames.cpp b/src/core/Frames.cpp
index c57e0ed2..6b0e96cc 100644
--- a/src/core/Frames.cpp
+++ b/src/core/Frames.cpp
@@ -35,7 +35,7 @@ namespace easy2d
this->Add(frames);
}
- Frames::Frames(Duration const& interval, Array const& frames)
+ Frames::Frames(Duration interval, Array const& frames)
: interval_(interval)
{
this->Add(frames);
@@ -45,7 +45,7 @@ namespace easy2d
{
}
- void Frames::SetInterval(Duration const& interval)
+ void Frames::SetInterval(Duration interval)
{
interval_ = interval;
}
@@ -68,7 +68,7 @@ namespace easy2d
}
}
- Duration const& Frames::GetInterval() const
+ Duration Frames::GetInterval() const
{
return interval_;
}
diff --git a/src/core/Frames.h b/src/core/Frames.h
index 7e27ec16..8cc41c1a 100644
--- a/src/core/Frames.h
+++ b/src/core/Frames.h
@@ -36,7 +36,7 @@ namespace easy2d
);
explicit Frames(
- Duration const& interval, /* 帧间隔 */
+ Duration interval, /* 帧间隔 */
Array const& frames /* 关键帧数组 */
);
@@ -53,14 +53,14 @@ namespace easy2d
);
// 获取帧间隔
- Duration const& GetInterval() const;
+ Duration GetInterval() const;
// 获取关键帧
Array const& GetFrames() const;
// 设置每一帧的时间间隔
void SetInterval(
- Duration const& interval
+ Duration interval
);
// 获取帧动画的拷贝对象
diff --git a/src/core/Node.cpp b/src/core/Node.cpp
index 435a1dcb..ff089c33 100644
--- a/src/core/Node.cpp
+++ b/src/core/Node.cpp
@@ -54,7 +54,7 @@ namespace easy2d
{
}
- void Node::Update(Duration const & dt)
+ void Node::Update(Duration dt)
{
if (pause_)
return;
diff --git a/src/core/Node.h b/src/core/Node.h
index c38395f7..b636ac7b 100644
--- a/src/core/Node.h
+++ b/src/core/Node.h
@@ -50,7 +50,7 @@ namespace easy2d
Node();
// 更新节点
- virtual void OnUpdate(Duration const& dt) {}
+ virtual void OnUpdate(Duration dt) {}
// 渲染节点
virtual void OnRender() {}
@@ -349,7 +349,7 @@ namespace easy2d
);
protected:
- void Update(Duration const& dt);
+ void Update(Duration dt);
void Render();
diff --git a/src/core/Task.cpp b/src/core/Task.cpp
index 140b5b68..53a4086a 100644
--- a/src/core/Task.cpp
+++ b/src/core/Task.cpp
@@ -27,7 +27,7 @@ namespace easy2d
{
}
- Task::Task(Callback const& func, Duration const& delay, int times, String const& name)
+ Task::Task(Callback const& func, Duration delay, int times, String const& name)
: running_(true)
, run_times_(0)
, total_times_(times)
@@ -48,7 +48,7 @@ namespace easy2d
running_ = false;
}
- void Task::Update(Duration const& dt, bool& remove_after_update)
+ void Task::Update(Duration dt, bool& remove_after_update)
{
if (!running_)
return;
diff --git a/src/core/Task.h b/src/core/Task.h
index 1640ec43..12411f29 100644
--- a/src/core/Task.h
+++ b/src/core/Task.h
@@ -46,7 +46,7 @@ namespace easy2d
explicit Task(
Callback const& func, /* 执行函数 */
- Duration const& delay, /* 时间间隔(秒) */
+ Duration delay, /* 时间间隔(秒) */
int times = -1, /* 执行次数(设 -1 为永久执行) */
String const& name = L"" /* 任务名称 */
);
@@ -64,7 +64,7 @@ namespace easy2d
String const& GetName() const;
protected:
- void Update(Duration const& dt, bool& remove_after_update);
+ void Update(Duration dt, bool& remove_after_update);
void Reset();
diff --git a/src/core/TaskManager.cpp b/src/core/TaskManager.cpp
index 53f9ff8c..9999beb1 100644
--- a/src/core/TaskManager.cpp
+++ b/src/core/TaskManager.cpp
@@ -23,7 +23,7 @@
namespace easy2d
{
- void TaskManager::UpdateTasks(Duration const& dt)
+ void TaskManager::UpdateTasks(Duration dt)
{
if (tasks_.IsEmpty())
return;
diff --git a/src/core/TaskManager.h b/src/core/TaskManager.h
index 0896dcc5..c5ad7b16 100644
--- a/src/core/TaskManager.h
+++ b/src/core/TaskManager.h
@@ -61,7 +61,7 @@ namespace easy2d
const Tasks& GetAllTasks() const;
protected:
- void UpdateTasks(Duration const& dt);
+ void UpdateTasks(Duration dt);
protected:
Tasks tasks_;
diff --git a/src/core/Transition.cpp b/src/core/Transition.cpp
index e6ac5930..b0be77fc 100644
--- a/src/core/Transition.cpp
+++ b/src/core/Transition.cpp
@@ -31,7 +31,7 @@ namespace easy2d
// Transition
//-------------------------------------------------------
- Transition::Transition(Duration const& duration)
+ Transition::Transition(Duration duration)
: done_(false)
, duration_(duration)
, delta_()
@@ -81,7 +81,7 @@ namespace easy2d
out_layer_prop_ = in_layer_prop_ = LayerProperties{ Rect(Point(), window_size_),1.f };
}
- void Transition::Update(Duration const& dt)
+ void Transition::Update(Duration dt)
{
if (duration_.IsZero())
{
@@ -142,7 +142,7 @@ namespace easy2d
// BoxTransition
//-------------------------------------------------------
- BoxTransition::BoxTransition(Duration const& duration)
+ BoxTransition::BoxTransition(Duration duration)
: Transition(duration)
{
}
@@ -154,7 +154,7 @@ namespace easy2d
in_layer_prop_.opacity = 0;
}
- void BoxTransition::Update(Duration const& dt)
+ void BoxTransition::Update(Duration dt)
{
Transition::Update(dt);
@@ -184,7 +184,7 @@ namespace easy2d
// EmergeTransition
//-------------------------------------------------------
- EmergeTransition::EmergeTransition(Duration const& duration)
+ EmergeTransition::EmergeTransition(Duration duration)
: Transition(duration)
{
}
@@ -197,7 +197,7 @@ namespace easy2d
in_layer_prop_.opacity = 0;
}
- void EmergeTransition::Update(Duration const& dt)
+ void EmergeTransition::Update(Duration dt)
{
Transition::Update(dt);
@@ -209,7 +209,7 @@ namespace easy2d
// FadeTransition
//-------------------------------------------------------
- FadeTransition::FadeTransition(Duration const& duration)
+ FadeTransition::FadeTransition(Duration duration)
: Transition(duration)
{
}
@@ -222,7 +222,7 @@ namespace easy2d
in_layer_prop_.opacity = 0;
}
- void FadeTransition::Update(Duration const& dt)
+ void FadeTransition::Update(Duration dt)
{
Transition::Update(dt);
@@ -242,7 +242,7 @@ namespace easy2d
// MoveTransition
//-------------------------------------------------------
- MoveTransition::MoveTransition(Duration const& duration, Direction direction)
+ MoveTransition::MoveTransition(Duration duration, Direction direction)
: Transition(duration)
, direction_(direction)
{
@@ -285,7 +285,7 @@ namespace easy2d
}
}
- void MoveTransition::Update(Duration const& dt)
+ void MoveTransition::Update(Duration dt)
{
Transition::Update(dt);
@@ -321,7 +321,7 @@ namespace easy2d
// RotationTransition
//-------------------------------------------------------
- RotationTransition::RotationTransition(Duration const& duration, float rotation)
+ RotationTransition::RotationTransition(Duration duration, float rotation)
: Transition(duration)
, rotation_(rotation)
{
@@ -349,7 +349,7 @@ namespace easy2d
in_layer_prop_.opacity = 0;
}
- void RotationTransition::Update(Duration const& dt)
+ void RotationTransition::Update(Duration dt)
{
Transition::Update(dt);
diff --git a/src/core/Transition.h b/src/core/Transition.h
index 5f04f3b5..206e43e5 100644
--- a/src/core/Transition.h
+++ b/src/core/Transition.h
@@ -34,7 +34,7 @@ namespace easy2d
public:
explicit Transition(
- Duration const& duration
+ Duration duration
);
virtual ~Transition();
@@ -47,7 +47,7 @@ namespace easy2d
ScenePtr const& next
);
- virtual void Update(Duration const& dt);
+ virtual void Update(Duration dt);
virtual void Render();
@@ -76,12 +76,12 @@ namespace easy2d
{
public:
explicit FadeTransition(
- Duration const& duration /* 动画持续时长 */
+ Duration duration /* 动画持续时长 */
);
protected:
// 更新动画
- virtual void Update(Duration const& dt) override;
+ virtual void Update(Duration dt) override;
virtual void Init(
ScenePtr const& prev,
@@ -96,11 +96,11 @@ namespace easy2d
{
public:
explicit EmergeTransition(
- Duration const& duration /* 动画持续时长 */
+ Duration duration /* 动画持续时长 */
);
protected:
- virtual void Update(Duration const& dt) override;
+ virtual void Update(Duration dt) override;
virtual void Init(
ScenePtr const& prev,
@@ -115,11 +115,11 @@ namespace easy2d
{
public:
explicit BoxTransition(
- Duration const& duration /* 动画持续时长 */
+ Duration duration /* 动画持续时长 */
);
protected:
- virtual void Update(Duration const& dt) override;
+ virtual void Update(Duration dt) override;
virtual void Init(
ScenePtr const& prev,
@@ -134,12 +134,12 @@ namespace easy2d
{
public:
explicit MoveTransition(
- Duration const& moveDuration, /* 动画持续时长 */
+ Duration moveDuration, /* 动画持续时长 */
Direction direction /* 移动方向 */
);
protected:
- virtual void Update(Duration const& dt) override;
+ virtual void Update(Duration dt) override;
virtual void Init(
ScenePtr const& prev,
@@ -161,12 +161,12 @@ namespace easy2d
{
public:
explicit RotationTransition(
- Duration const& moveDuration, /* 动画持续时长 */
+ Duration moveDuration, /* 动画持续时长 */
float rotation = 360 /* 旋转度数 */
);
protected:
- virtual void Update(Duration const& dt) override;
+ virtual void Update(Duration dt) override;
virtual void Init(
ScenePtr const& prev,
diff --git a/src/core/helper.hpp b/src/core/helper.hpp
index b8b25cde..7cfa6444 100644
--- a/src/core/helper.hpp
+++ b/src/core/helper.hpp
@@ -97,7 +97,7 @@ namespace easy2d
E2D_DECLARE_SMART_PTR(GeometryNode);
E2D_DECLARE_SMART_PTR(Action);
- E2D_DECLARE_SMART_PTR(Tween);
+ E2D_DECLARE_SMART_PTR(ActionTween);
E2D_DECLARE_SMART_PTR(MoveBy);
E2D_DECLARE_SMART_PTR(MoveTo);
E2D_DECLARE_SMART_PTR(JumpBy);
diff --git a/src/core/time.cpp b/src/core/time.cpp
index 90a65df0..5001d22e 100644
--- a/src/core/time.cpp
+++ b/src/core/time.cpp
@@ -40,16 +40,6 @@ namespace easy2d
{
}
- TimePoint::TimePoint(const TimePoint & other)
- : dur(other.dur)
- {
- }
-
- TimePoint::TimePoint(TimePoint && other)
- : dur(std::move(other.dur))
- {
- }
-
const TimePoint TimePoint::operator+(const Duration & dur) const
{
return TimePoint{ (dur + dur).Milliseconds() };
@@ -100,7 +90,7 @@ namespace easy2d
// Duration
//-------------------------------------------------------
- const Duration Millisecond = Duration{ 1LL };
+ const Duration Millisecond = 1L;
const Duration Second = 1000 * Millisecond;
const Duration Minute = 60 * Second;
const Duration Hour = 60 * Minute;
diff --git a/src/core/time.h b/src/core/time.h
index dcc3d56c..433098ef 100644
--- a/src/core/time.h
+++ b/src/core/time.h
@@ -36,9 +36,8 @@ namespace easy2d
// 1.5 小时: 1.5_h
// 3 小时 45 分 15 秒: 3_h + 45_m + 15_s
//
- class Duration
+ struct Duration
{
- public:
Duration();
Duration(
@@ -122,22 +121,11 @@ namespace easy2d
// TimePoint t1, t2;
// int ms = (t2 - t1).Milliseconds(); // 获取两时间相差的毫秒数
//
- class TimePoint
+ struct TimePoint
{
- public:
TimePoint();
- TimePoint(
- long
- );
-
- TimePoint(
- const TimePoint& other
- );
-
- TimePoint(
- TimePoint&& other
- );
+ TimePoint(long);
// 是否是零时
inline bool IsZero() const { return dur == 0; }
diff --git a/src/easy2d.h b/src/easy2d.h
index 23bb7b11..4ebe0aaa 100644
--- a/src/easy2d.h
+++ b/src/easy2d.h
@@ -58,8 +58,9 @@
#include "core/Task.h"
#include "core/TaskManager.h"
#include "core/Action.hpp"
-#include "core/ActionCombined.h"
+#include "core/ActionGroup.h"
#include "core/ActionTween.h"
+#include "core/ActionHelper.h"
#include "core/Animation.h"
#include "core/Delay.h"
#include "core/ActionManager.h"