diff options
| author | KonAki <konaki@anokonaki.org> | 2026-10-12 13:45:23 +0800 |
|---|---|---|
| committer | KonAki <konaki@anokonaki.org> | 2026-10-12 13:45:23 +0800 |
| commit | 79edd4027ab956c441c660367c497508c99696bb (patch) | |
| tree | ebcde84b982ebaa527ced4d23d59858ae89c14f8 /kon/kon2d.h | |
| parent | 25bb4216fd726824c237a00c8ca0ee23b39d995e (diff) | |
add 2d module: camera, frame animation, tweens
Diffstat (limited to 'kon/kon2d.h')
| -rw-r--r-- | kon/kon2d.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/kon/kon2d.h b/kon/kon2d.h index fce4bb2..badaed0 100644 --- a/kon/kon2d.h +++ b/kon/kon2d.h @@ -72,4 +72,35 @@ int kon_animDone(const kon_anim_t *anim); /* draws frame index of a sheet of frameWidth by frameHeight frames with its top left at x, y */ void kon_drawFrame(kon_framebuffer_t *fb, const kon_image *sheet, int frameWidth, int frameHeight, int index, int x, int y, int flip); +/*** tweens ***/ + +typedef enum kon_ease { + KON_EASE_LINEAR, + KON_EASE_IN, /* starts slow */ + KON_EASE_OUT, /* ends slow */ + KON_EASE_INOUT +} kon_ease_t; + +/* a number that glides from one value to another. start one with kon_tweenStart, feed it time with kon_tweenStep and read it with + kon_tweenValue. a tween that was never started just holds 0, kon_tweenSet gives it a value to hold */ +typedef struct kon_tween { + float from, to; + float duration, time; + kon_ease_t ease; +} kon_tween_t; + +/* t from 0 to 1, out of range is clamped */ +float kon_easeValue(kon_ease_t ease, float t); + +void kon_tweenSet(kon_tween_t *tween, float value); +void kon_tweenStart(kon_tween_t *tween, float from, float to, float seconds, kon_ease_t ease); + +/* glides from wherever it is now, so it can be redirected in the middle of a move */ +void kon_tweenTo(kon_tween_t *tween, float to, float seconds, kon_ease_t ease); + +/* returns the new value */ +float kon_tweenStep(kon_tween_t *tween, float dt); +float kon_tweenValue(const kon_tween_t *tween); +int kon_tweenDone(const kon_tween_t *tween); + #endif |
