我正在渲染正在分发的卡片。玩家的卡片在屏幕底部,荷官的卡片在更上面。卡片从屏幕顶部的“看不见的地方”分发。因此,卡片起始位置与玩家手牌之间的距离比起始位置和荷官手牌之间的距离更远。
我正在使用介于0.0
和1.0
之间的interpolated_position
值来计算卡片的当前位置。由于距离不同,动画速度也不同。
/// Updates the first animation in the queue then deletes it
void Update(float delta_time)
{
if (pause == false && !animation_confs.empty())
{
interpolated_position += delta_time * (animation_confs[0].speed); // animation speed is 1.3 here
if (interpolated_position >= 1.0f) // Finished animation reset values
{
interpolated_position = 0.0f;
if (!animation_confs.empty())
{
animation_confs.erase(animation_confs.begin());
return;
}
}
InterpolateFrame();
}
}
// Interpolates card position between two points based on interpolation factor
void InterpolateFrame()
{
if (!animation_confs.empty())
{
float t = interpolated_position;
float x1 = animation_confs[0].start.x;
float x2 = animation_confs[0].goal.x;
position.x = x1 + t * (x2 - x1);
float y1 = animation_confs[0].start.y;
float y2 = animation_confs[0].goal.y;
position.y = y1 + t * (y2 - y1);
}
}
这种行为的原因是什么?我认为将
delta_time
应用于插值应该可以保持速度恒定。
![](https://istack.dev59.com/8HmVF.gif)