mirror of
https://github.com/FunKey-Project/RetroFE.git
synced 2026-04-02 02:05:55 +02:00
Smoother tween transitions
This commit is contained in:
@@ -27,18 +27,25 @@ Component::Component()
|
||||
}
|
||||
void Component::addAnimation(const ComponentData &newInfo)
|
||||
{
|
||||
animations.push_back(newInfo);
|
||||
startInfo = &info;
|
||||
endInfo = &animations[0];
|
||||
elapsedTime = 0;
|
||||
animationIndex = 0;
|
||||
start = false;
|
||||
animations.push_back(newInfo);
|
||||
elapsedTime = 0;
|
||||
}
|
||||
|
||||
void Component::animate(bool loop)
|
||||
{
|
||||
this->loop = loop;
|
||||
this->start = true;
|
||||
start = true;
|
||||
elapsedTime = 0;
|
||||
animationIndex = -1;
|
||||
|
||||
startInfo = &info;
|
||||
endInfo = &info;
|
||||
|
||||
if(animations.size() > 0)
|
||||
{
|
||||
endInfo = &animations[0];
|
||||
}
|
||||
}
|
||||
|
||||
double linear(double t, double d, double b, double c)
|
||||
@@ -48,7 +55,7 @@ double linear(double t, double d, double b, double c)
|
||||
}
|
||||
void Component::update(float dt)
|
||||
{
|
||||
elapsedTime += dt;
|
||||
elapsedTime += dt;
|
||||
bool done = false;
|
||||
while(elapsedTime >= endInfo->duration) {
|
||||
elapsedTime -= endInfo->duration;
|
||||
|
||||
@@ -221,6 +221,21 @@ void RetroFE::run()
|
||||
double deltaTime = 0;
|
||||
while(!quit) {
|
||||
|
||||
lastTime = currentTime;
|
||||
currentTime = static_cast<float>(SDL_GetTicks()) / 1000;
|
||||
|
||||
if(lastTime == 0)
|
||||
{
|
||||
lastTime = currentTime;
|
||||
}
|
||||
|
||||
if (currentTime < lastTime)
|
||||
{
|
||||
currentTime = lastTime;
|
||||
}
|
||||
|
||||
deltaTime = currentTime - lastTime;
|
||||
|
||||
SDL_LockMutex(SDL::getMutex());
|
||||
SDL_SetRenderDrawColor(SDL::getRenderer(), 0x0, 0x0, 0x00, 0xFF);
|
||||
SDL_RenderClear(SDL::getRenderer());
|
||||
@@ -238,15 +253,6 @@ void RetroFE::run()
|
||||
SDL_RenderPresent(SDL::getRenderer());
|
||||
SDL_UnlockMutex(SDL::getMutex());
|
||||
|
||||
lastTime = currentTime;
|
||||
currentTime = static_cast<float>(SDL_GetTicks()) / 1000;
|
||||
|
||||
if (currentTime < lastTime)
|
||||
{
|
||||
currentTime = lastTime;
|
||||
}
|
||||
|
||||
deltaTime = currentTime - lastTime;
|
||||
double sleepTime = 1000.0/60.0 - deltaTime*1000;
|
||||
if(sleepTime > 0)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user