mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-02-07 21:56:44 +01:00
tween: pre/post-delay support, StaticTween helper
This commit is contained in:
parent
4754d8dd4e
commit
9d9d23dfe8
2 changed files with 21 additions and 1 deletions
20
src/tween.c
20
src/tween.c
|
@ -253,10 +253,16 @@ SYMBOL_EXPORT struct Tween Tween(struct Game* game, double start, double stop, T
|
|||
.paused = false,
|
||||
.game = game,
|
||||
.done = false,
|
||||
.predelay = 0,
|
||||
.postdelay = 0,
|
||||
.callback = NULL,
|
||||
.data = NULL};
|
||||
}
|
||||
|
||||
SYMBOL_EXPORT struct Tween StaticTween(struct Game* game, double value) {
|
||||
return Tween(game, value, value, TWEEN_STYLE_LINEAR, 0);
|
||||
}
|
||||
|
||||
SYMBOL_EXPORT double GetTweenPosition(struct Tween* tween) {
|
||||
if (tween->duration == 0.0) {
|
||||
return 1.0;
|
||||
|
@ -348,10 +354,22 @@ SYMBOL_EXPORT double GetTweenValue(struct Tween* tween) {
|
|||
|
||||
SYMBOL_EXPORT void UpdateTween(struct Tween* tween, double delta) {
|
||||
if (tween->paused) { return; }
|
||||
if (tween->predelay) {
|
||||
tween->predelay -= delta;
|
||||
if (tween->predelay > 0) {
|
||||
return;
|
||||
} else if (tween->predelay < 0) {
|
||||
delta = -tween->predelay;
|
||||
tween->predelay = 0;
|
||||
}
|
||||
}
|
||||
tween->pos += delta;
|
||||
if (tween->pos > tween->duration) {
|
||||
tween->pos = tween->duration;
|
||||
if (!tween->done) {
|
||||
if (tween->postdelay) {
|
||||
tween->postdelay -= delta;
|
||||
}
|
||||
if ((tween->postdelay <= 0) && (!tween->done)) {
|
||||
tween->done = true;
|
||||
if (tween->callback) {
|
||||
tween->callback(tween->game, tween, tween->data);
|
||||
|
|
|
@ -71,6 +71,7 @@ typedef enum TWEEN_STYLE {
|
|||
struct Tween {
|
||||
double start, stop;
|
||||
double duration, pos;
|
||||
double predelay, postdelay;
|
||||
TWEEN_STYLE style;
|
||||
bool paused;
|
||||
bool done;
|
||||
|
@ -80,6 +81,7 @@ struct Tween {
|
|||
};
|
||||
|
||||
struct Tween Tween(struct Game* game, double start, double stop, TWEEN_STYLE style, double duration);
|
||||
struct Tween StaticTween(struct Game* game, double value);
|
||||
double GetTweenPosition(struct Tween* tween);
|
||||
double GetTweenInterpolation(struct Tween* tween);
|
||||
double GetTweenValue(struct Tween* tween);
|
||||
|
|
Loading…
Reference in a new issue