我正在构建一个图像预加载动画,这是一个绘制的圆圈/饼图。每个“切片”都是 totalImages / imagesLoaded。因此,如果有 4 张图像和 2 张已加载,它应该随着时间的推移绘制到 180。
我正在使用 requestAnimFrame,它工作得很好,而且我有一个 deltaTime 设置来限制动画的时间,但是我在数学上遇到了麻烦。我能得到的最接近的是它动画并缓和到它应该在的位置附近,但随后值增量变得越来越小。本质上它永远不会达到完成的价值。(例如,如果加载了一张图像,则为 90 度)。
var totalImages = 4;
var imagesLoaded = 1;
var currentArc = 0;
function drawPie(){
var newArc = 360 / totalImages * this.imagesLoaded // Get the value in degrees that we should animate to
var percentage = (isNaN(currentArc / newArc) || !isFinite(currentArc / newArc)) || (currentArc / newArc) > 1 ? 1 : (currentArc / newArc); // Dividing these two numbers sometimes returned NaN or Infinity/-Infinity, so this is a fallback
var easeValue = easeInOutExpo(percentage, 0, newArc, 1);
//This animates continuously (Obviously), because it's just constantly adding to itself:
currentArc += easedValue * this.time.delta;
OR
//This never reaches the full amount, as increments get infinitely smaller
currentArc += (newArc - easedValue) * this.time.delta;
}
function easeInOutExpo(t, b, c, d){
return c*((t=t/d-1)*t*t + 1) + b;
}
我觉得我拥有所有正确的元素和价值观。我只是将它们错误地放在一起。
任何和所有的帮助表示赞赏。