add: EaseFunction maker
This commit is contained in:
parent
098167c606
commit
d88fc5afbe
|
|
@ -22,7 +22,6 @@
|
||||||
#include "Geometry.h"
|
#include "Geometry.h"
|
||||||
#include "base.hpp"
|
#include "base.hpp"
|
||||||
#include "Node.h"
|
#include "Node.h"
|
||||||
#include "../math/ease.hpp"
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cfloat>
|
#include <cfloat>
|
||||||
|
|
||||||
|
|
@ -58,13 +57,13 @@ namespace easy2d
|
||||||
ease_func_ = math::Linear;
|
ease_func_ = math::Linear;
|
||||||
break;
|
break;
|
||||||
case EaseFunc::EaseIn:
|
case EaseFunc::EaseIn:
|
||||||
ease_func_ = std::bind(math::EaseIn, std::placeholders::_1, 2.f);
|
ease_func_ = MakeEaseIn(2.f);
|
||||||
break;
|
break;
|
||||||
case EaseFunc::EaseOut:
|
case EaseFunc::EaseOut:
|
||||||
ease_func_ = std::bind(math::EaseOut, std::placeholders::_1, 2.f);
|
ease_func_ = MakeEaseOut(2.f);
|
||||||
break;
|
break;
|
||||||
case EaseFunc::EaseInOut:
|
case EaseFunc::EaseInOut:
|
||||||
ease_func_ = std::bind(math::EaseInOut, std::placeholders::_1, 2.f);
|
ease_func_ = MakeEaseInOut(2.f);
|
||||||
break;
|
break;
|
||||||
case EaseFunc::EaseExponentialIn:
|
case EaseFunc::EaseExponentialIn:
|
||||||
ease_func_ = math::EaseExponentialIn;
|
ease_func_ = math::EaseExponentialIn;
|
||||||
|
|
@ -85,13 +84,13 @@ namespace easy2d
|
||||||
ease_func_ = math::EaseBounceInOut;
|
ease_func_ = math::EaseBounceInOut;
|
||||||
break;
|
break;
|
||||||
case EaseFunc::EaseElasticIn:
|
case EaseFunc::EaseElasticIn:
|
||||||
ease_func_ = std::bind(math::EaseElasticIn, std::placeholders::_1, 0.3f);
|
ease_func_ = MakeEaseElasticIn(0.3f);
|
||||||
break;
|
break;
|
||||||
case EaseFunc::EaseElasticOut:
|
case EaseFunc::EaseElasticOut:
|
||||||
ease_func_ = std::bind(math::EaseElasticOut, std::placeholders::_1, 0.3f);
|
ease_func_ = MakeEaseElasticOut(0.3f);
|
||||||
break;
|
break;
|
||||||
case EaseFunc::EaseElasticInOut:
|
case EaseFunc::EaseElasticInOut:
|
||||||
ease_func_ = std::bind(math::EaseElasticInOut, std::placeholders::_1, 0.3f);
|
ease_func_ = MakeEaseElasticInOut(0.3f);
|
||||||
break;
|
break;
|
||||||
case EaseFunc::EaseSineIn:
|
case EaseFunc::EaseSineIn:
|
||||||
ease_func_ = math::EaseSineIn;
|
ease_func_ = math::EaseSineIn;
|
||||||
|
|
@ -107,7 +106,7 @@ namespace easy2d
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tween::SetEaseFunction(std::function<float(float)> func)
|
void Tween::SetEaseFunction(EaseFunction func)
|
||||||
{
|
{
|
||||||
ease_func_ = func;
|
ease_func_ = func;
|
||||||
ease_type_ = EaseFunc(-1);
|
ease_type_ = EaseFunc(-1);
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "Action.hpp"
|
#include "Action.hpp"
|
||||||
#include "logs.h"
|
#include "logs.h"
|
||||||
|
#include "../math/ease.hpp"
|
||||||
|
|
||||||
namespace easy2d
|
namespace easy2d
|
||||||
{
|
{
|
||||||
|
|
@ -44,6 +45,15 @@ namespace easy2d
|
||||||
EaseSineInOut, // 譚찹逞우, 疼譚우逞찹, 꽃痰攣菊긴뻣醵똑
|
EaseSineInOut, // 譚찹逞우, 疼譚우逞찹, 꽃痰攣菊긴뻣醵똑
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using EaseFunction = std::function<float(float)>;
|
||||||
|
|
||||||
|
inline EaseFunction MakeEaseIn(float rate) { return std::bind(math::EaseIn, std::placeholders::_1, rate); }
|
||||||
|
inline EaseFunction MakeEaseOut(float rate) { return std::bind(math::EaseOut, std::placeholders::_1, rate); }
|
||||||
|
inline EaseFunction MakeEaseInOut(float rate) { return std::bind(math::EaseInOut, std::placeholders::_1, rate); }
|
||||||
|
inline EaseFunction MakeEaseElasticIn(float period) { return std::bind(math::EaseElasticIn, std::placeholders::_1, period); }
|
||||||
|
inline EaseFunction MakeEaseElasticOut(float period) { return std::bind(math::EaseElasticOut, std::placeholders::_1, period); }
|
||||||
|
inline EaseFunction MakeEaseElasticInOut(float period) { return std::bind(math::EaseElasticInOut, std::placeholders::_1, period); }
|
||||||
|
|
||||||
class Tween
|
class Tween
|
||||||
: public Action
|
: public Action
|
||||||
{
|
{
|
||||||
|
|
@ -62,7 +72,7 @@ namespace easy2d
|
||||||
|
|
||||||
// 菱땍屢醵똑긴뺏혓窟
|
// 菱땍屢醵똑긴뺏혓窟
|
||||||
void SetEaseFunction(
|
void SetEaseFunction(
|
||||||
std::function<float(float)> func
|
EaseFunction func
|
||||||
);
|
);
|
||||||
|
|
||||||
virtual void Reset() override;
|
virtual void Reset() override;
|
||||||
|
|
@ -79,10 +89,10 @@ namespace easy2d
|
||||||
virtual void UpdateStep(Node* target, float step) = 0;
|
virtual void UpdateStep(Node* target, float step) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Duration duration_;
|
Duration duration_;
|
||||||
Duration elapsed_;
|
Duration elapsed_;
|
||||||
EaseFunc ease_type_;
|
EaseFunc ease_type_;
|
||||||
std::function<float(float)> ease_func_;
|
EaseFunction ease_func_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue