mirror of
https://gitlab.com/dosowisko.net/libsuperderpy.git
synced 2025-02-01 11:06:44 +01:00
tween: add ability to store a custom tweening function with the Tween object
This commit is contained in:
parent
9d9d23dfe8
commit
a68e15e274
2 changed files with 10 additions and 1 deletions
|
@ -256,6 +256,7 @@ SYMBOL_EXPORT struct Tween Tween(struct Game* game, double start, double stop, T
|
||||||
.predelay = 0,
|
.predelay = 0,
|
||||||
.postdelay = 0,
|
.postdelay = 0,
|
||||||
.callback = NULL,
|
.callback = NULL,
|
||||||
|
.func = NULL,
|
||||||
.data = NULL};
|
.data = NULL};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,11 +341,16 @@ SYMBOL_EXPORT double Interpolate(double pos, TWEEN_STYLE style) {
|
||||||
return BounceEaseOut(pos);
|
return BounceEaseOut(pos);
|
||||||
case TWEEN_STYLE_BOUNCE_IN_OUT:
|
case TWEEN_STYLE_BOUNCE_IN_OUT:
|
||||||
return BounceEaseInOut(pos);
|
return BounceEaseInOut(pos);
|
||||||
|
default:
|
||||||
|
return pos;
|
||||||
}
|
}
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
SYMBOL_EXPORT double GetTweenInterpolation(struct Tween* tween) {
|
SYMBOL_EXPORT double GetTweenInterpolation(struct Tween* tween) {
|
||||||
|
if (tween->style == TWEEN_STYLE_CUSTOM && tween->func) {
|
||||||
|
return tween->func(GetTweenPosition(tween));
|
||||||
|
}
|
||||||
return Interpolate(GetTweenPosition(tween), tween->style);
|
return Interpolate(GetTweenPosition(tween), tween->style);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,9 @@ typedef enum TWEEN_STYLE {
|
||||||
// Exponentially-decaying bounce easing
|
// Exponentially-decaying bounce easing
|
||||||
TWEEN_STYLE_BOUNCE_IN,
|
TWEEN_STYLE_BOUNCE_IN,
|
||||||
TWEEN_STYLE_BOUNCE_OUT,
|
TWEEN_STYLE_BOUNCE_OUT,
|
||||||
TWEEN_STYLE_BOUNCE_IN_OUT
|
TWEEN_STYLE_BOUNCE_IN_OUT,
|
||||||
|
// Custom callback
|
||||||
|
TWEEN_STYLE_CUSTOM
|
||||||
} TWEEN_STYLE; // Cheet sheet at http://easings.net/ :)
|
} TWEEN_STYLE; // Cheet sheet at http://easings.net/ :)
|
||||||
|
|
||||||
struct Tween {
|
struct Tween {
|
||||||
|
@ -76,6 +78,7 @@ struct Tween {
|
||||||
bool paused;
|
bool paused;
|
||||||
bool done;
|
bool done;
|
||||||
struct Game* game;
|
struct Game* game;
|
||||||
|
double (*func)(double value);
|
||||||
void (*callback)(struct Game* game, struct Tween* tween, void* data);
|
void (*callback)(struct Game* game, struct Tween* tween, void* data);
|
||||||
void* data;
|
void* data;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue