2

我目前正在使用 SFML 在 c++ 中创建一个徽标序列,并且想输入所需的时间然后淡出该时间量,例如,如果输入为 3,则淡出颜色直到 3 秒结束。颜色整数的最大数量,作为一种颜色是 255 作为白色。这是我当前的代码:

sf::Time fadeCalc = clock.getElapsedTime();
int f = fadeCalc.asMilliseconds();
int l = logoLength.asSeconds();
int iColor = "Equation needed using variables"
sf::Color fadeColor(iColor,iColor,iColor);
Fade.setFillColor(fadeColor);

任何帮助将不胜感激!对不起,我想不出一种更容易解释的方法。

4

1 回答 1

2

您将逐渐淡出,start color每次平局迈出一步。end colortotal fade timeelapsed time

因此,在每个绘制步骤中,您都需要将颜色设置为start color + ((end color - start color) * (elapsed time / total time))。这将为您提供您想要完成的更改量,计算此时应该发生的更改百分比,然后将更改的金额添加到您的初始金额。

例如,如果您想从 100 变为 255,并且它在 3000 毫秒中是 1000,那么您希望是从 100 到 255 的 1/3,或 151.6667(151 被截断)。在 2/3 处,它将是 203.333。等等。

一旦您 >= your total time,只需设置start colorend color.

于 2013-02-23T05:14:57.470 回答