26inline static const std::function
LinearEase = [](
float current,
float total)
28 return current / total;
38 std::function<
void(
GameObject*,
const T&)> funcToCall,
39 std::function<
float(
float,
float)> EasingFunction =
ac::LinearEase)
58 getInternalParent()->destroyed())
101#pragma region actions
104 assert(parent &&
"TranslateAction given a nullptr");
105 if (
auto parentAsEntity =
dynamic_cast<Entity*
>(parent))
109 parentTransform->translation(newTranslation);
117 assert(parent &&
"TranslateAction given a nullptr");
118 if (
auto parentAsEntity =
dynamic_cast<Entity*
>(parent))
122 parentTransform->scale(newScale);
130 assert(parent &&
"SetColorAction given a nullptr");
131 if (
auto parentAsEntity =
dynamic_cast<Entity*
>(parent))
135 parentSprite->color() = newColor;
142#pragma region ease_functions
147inline static const std::function
easeInOutBack = [](
float current,
float total)
149 constexpr auto c1 = 1.70158f;
150 constexpr auto c2 = c1 * 1.525f;
152 auto progress = current / total;
156 return (pow(2 * total, 2) * ((c2 + 1) * 2 * total - c2)) / 2;
159 return (pow(2 * total - 2, 2) * ((c2 + 1) * (total * 2 - 2) + c2) + 2) / 2;
167 auto progress = current / total;
169 if (progress == 0 || progress == 1)
173 return static_cast<float>(pow(2, -10 * progress) * sin((progress * 10 - 0.75f) * (2 * std::numbers::pi / 3.f)) + 1);
178inline static const std::function
easeOutBounce = [](
float current,
float total)
180 constexpr auto n1 = 7.5625f;
182 if (current < 1 / total)
184 return n1 * current * current;
187 if (current < 2 / total)
189 return n1 * (current -= 1.5f / total) * current + 0.75f;
192 if (current < 2.5f / total)
194 return n1 * (current -= 2.25f / total) * current + 0.9375f;
196 return n1 * (current -= 2.625f / total) * current + 0.984375f;
201 return current < 0.5f
The class containing all entity elements.
Action(T start, T end, float totalTime, GameObject *actionOwner, std::function< void(GameObject *, const T &)> funcToCall, std::function< float(float, float)> EasingFunction=ac::LinearEase)
Definition Action.h:37
std::function< float(float, float)> easingFunction
Definition Action.h:92
std::function< void(GameObject *, const T &)> dataUpdate
Definition Action.h:91
T endValue
Definition Action.h:86
T startValue
Definition Action.h:85
float currentTime
Definition Action.h:88
auto shouldRemove() const -> bool
Definition Action.h:66
float totalDuration
Definition Action.h:87
auto update(float dt) -> void
Definition Action.h:50
auto render() const -> void
Definition Action.h:74
GameObject * changingObject
Definition Action.h:89
auto setOwner(GameObject *newObject) -> void
Definition Action.h:79
@ cTransform
Definition Component.h:39
@ cSprite
Definition Component.h:41
the base class for the engine, most things inherit from this.
Definition GameObject.h:77
A component that renders an image on an entity, or text.
Definition Sprite.h:34
static const std::function ScaleAction
Definition Action.h:115
static const std::function LinearEase
Definition Action.h:26
static const std::function EaseInOutBounce
Definition Action.h:199
static const std::function TranslateAction
Definition Action.h:102
static const std::function easeOutElastic
Definition Action.h:164
static const std::function SetColorAction
Definition Action.h:128
static const std::function easeInOutBack
Definition Action.h:147
static const std::function easeOutBounce
Definition Action.h:178