关于我在可汗学院用 Javascript 编写的游戏引擎的快速问题:我在弧上表示剩余的重新加载时间。(在处理 js 时,画一个圆弧是这样的arc(x,y,width,height,start,stop);
:)
我已经将剩余时间的值(以秒为单位)存储在变量中,那么我怎样才能准确地将弧楔 = 当前重新加载的时间除以总重新加载时间?
当圆弧为圆时,重新加载完成。当 arc 什么都没有时,它才开始重新加载。
此外,重新加载弧形楔形冲程从中心顶部开始,并围绕外侧顺时针移动。
if(weapon.reloading){
arc(300,300-player.size-player.size/2,40,40,-90,round((w.reloadCounter/w.reloadTime/100)*100)*6-95);
}
当 fps(每秒帧数等于 60)时,此冗余代码有效我已经有一个名为 fps 的变量等于每秒帧数,因此如果提供任何帮助,请在示例中使用它。
谢谢!
编辑:这是否准确 - 从我从测试中可以看出,它大多是准确的:
var time = round(w.reloadCounter/fps*10)/10;//seconds currently spent reloading(rounded to the nearest 10th)
var t = round((w.reloadTime-time)*10)/10;//time left to finish reloading
var timeLeftArc = map(t,0,w.reloadTime,270,-90);
arc(300,300-player.size-player.size/2,40,40,-90,timeLeftArc);