Smoother tween transitions

This commit is contained in:
emb
2015-11-09 23:59:08 -06:00
parent 9ca9d022c0
commit f30fe6cc7e
2 changed files with 29 additions and 16 deletions

View File

@@ -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;

View File

@@ -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)
{