小编Geo*_*nts的帖子

渲染画布的速度超过每秒 60 次?

我的JS代码:

var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");

var mouse = {x:0,y:0}

const times = [];
let fps;

function refreshLoop() {
  window.requestAnimationFrame(() => {
    const now = performance.now();
    while (times.length > 0 && times[0] <= now - 1000) {
      times.shift();
    }
    times.push(now);
    fps = times.length;
    refreshLoop();
  });
}

refreshLoop();

function draw() {
  ctx.fillStyle = "black"
  ctx.fillRect(0, 0, c.width, c.height);
  ctx.strokeStyle = "white"
  ctx.beginPath();
  var e = window.event;
  ctx.arc(mouse.x, mouse.y, 40, 0, 2*Math.PI);
  ctx.stroke();
  ctx.font = "30px Comic Sans MS"; …
Run Code Online (Sandbox Code Playgroud)

javascript canvas vsync low-latency

4
推荐指数
1
解决办法
2270
查看次数

标签 统计

canvas ×1

javascript ×1

low-latency ×1

vsync ×1