mirror of
https://github.com/bjornbytes/lovr.git
synced 2024-07-04 13:33:34 +00:00
Animator:play; Animator:stop; Animator:pause; Animator:resume;
This commit is contained in:
parent
4249cb4cc6
commit
23b4750e9c
|
@ -14,8 +14,40 @@ int l_lovrAnimatorUpdate(lua_State* L) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int l_lovrAnimatorPlay(lua_State* L) {
|
||||||
|
Animator* animator = luax_checktype(L, 1, Animator);
|
||||||
|
const char* animation = luaL_checkstring(L, 2);
|
||||||
|
lovrAnimatorPlay(animator, animation);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int l_lovrAnimatorStop(lua_State* L) {
|
||||||
|
Animator* animator = luax_checktype(L, 1, Animator);
|
||||||
|
const char* animation = luaL_checkstring(L, 2);
|
||||||
|
lovrAnimatorStop(animator, animation);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int l_lovrAnimatorPause(lua_State* L) {
|
||||||
|
Animator* animator = luax_checktype(L, 1, Animator);
|
||||||
|
const char* animation = luaL_checkstring(L, 2);
|
||||||
|
lovrAnimatorPause(animator, animation);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int l_lovrAnimatorResume(lua_State* L) {
|
||||||
|
Animator* animator = luax_checktype(L, 1, Animator);
|
||||||
|
const char* animation = luaL_checkstring(L, 2);
|
||||||
|
lovrAnimatorResume(animator, animation);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
const luaL_Reg lovrAnimator[] = {
|
const luaL_Reg lovrAnimator[] = {
|
||||||
{ "getAnimationCount", l_lovrAnimatorGetAnimationCount },
|
{ "getAnimationCount", l_lovrAnimatorGetAnimationCount },
|
||||||
{ "update", l_lovrAnimatorUpdate },
|
{ "update", l_lovrAnimatorUpdate },
|
||||||
|
{ "play", l_lovrAnimatorPlay },
|
||||||
|
{ "stop", l_lovrAnimatorStop },
|
||||||
|
{ "pause", l_lovrAnimatorPause },
|
||||||
|
{ "resume", l_lovrAnimatorResume },
|
||||||
{ NULL, NULL }
|
{ NULL, NULL }
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,5 +1,11 @@
|
||||||
#include "graphics/animator.h"
|
#include "graphics/animator.h"
|
||||||
|
|
||||||
|
static Track* lovrAnimatorEnsureTrack(Animator* animator, const char* animation) {
|
||||||
|
Track* track = map_get(&animator->timeline, animation);
|
||||||
|
lovrAssert(track, "Animation '%s' does not exist", animation);
|
||||||
|
return track;
|
||||||
|
}
|
||||||
|
|
||||||
Animator* lovrAnimatorCreate(AnimationData* animationData) {
|
Animator* lovrAnimatorCreate(AnimationData* animationData) {
|
||||||
Animator* animator = lovrAlloc(sizeof(Animator), lovrAnimatorDestroy);
|
Animator* animator = lovrAlloc(sizeof(Animator), lovrAnimatorDestroy);
|
||||||
if (!animator) return NULL;
|
if (!animator) return NULL;
|
||||||
|
@ -40,3 +46,25 @@ void lovrAnimatorUpdate(Animator* animator, float dt) {
|
||||||
track->time += dt * track->speed * animator->speed;
|
track->time += dt * track->speed * animator->speed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void lovrAnimatorPlay(Animator* animator, const char* animation) {
|
||||||
|
Track* track = lovrAnimatorEnsureTrack(animator, animation);
|
||||||
|
track->playing = true;
|
||||||
|
track->time = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void lovrAnimatorStop(Animator* animator, const char* animation) {
|
||||||
|
Track* track = lovrAnimatorEnsureTrack(animator, animation);
|
||||||
|
track->playing = false;
|
||||||
|
track->time = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void lovrAnimatorPause(Animator* animator, const char* animation) {
|
||||||
|
Track* track = lovrAnimatorEnsureTrack(animator, animation);
|
||||||
|
track->playing = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void lovrAnimatorResume(Animator* animator, const char* animation) {
|
||||||
|
Track* track = lovrAnimatorEnsureTrack(animator, animation);
|
||||||
|
track->playing = true;
|
||||||
|
}
|
||||||
|
|
|
@ -25,3 +25,7 @@ Animator* lovrAnimatorCreate(AnimationData* animationData);
|
||||||
void lovrAnimatorDestroy(const Ref* ref);
|
void lovrAnimatorDestroy(const Ref* ref);
|
||||||
int lovrAnimatorGetAnimationCount(Animator* animator);
|
int lovrAnimatorGetAnimationCount(Animator* animator);
|
||||||
void lovrAnimatorUpdate(Animator* animator, float dt);
|
void lovrAnimatorUpdate(Animator* animator, float dt);
|
||||||
|
void lovrAnimatorPlay(Animator* animator, const char* animation);
|
||||||
|
void lovrAnimatorStop(Animator* animator, const char* animation);
|
||||||
|
void lovrAnimatorPause(Animator* animator, const char* animation);
|
||||||
|
void lovrAnimatorResume(Animator* animator, const char* animation);
|
||||||
|
|
Loading…
Reference in a new issue