INNER CODE UNIT · JavaScript

fixCanvasDpr

shixiangxi0/Cobweb · clients/phaser/src/main.js:96

function fixCanvasDpr() {
  const canvas = game.canvas;
  if (!canvas) return;
  const dpr = Math.max(1, window.devicePixelRatio || 1);
  const cssW = Math.round(canvas.clientWidth);
  const cssH = Math.round(canvas.clientHeight);
  const targetW = Math.round(cssW * dpr);
  const targetH = Math.round(cssH * dpr);

  if (canvas.width !== targetW || canvas.height !== targetH) {
    canvas.width = targetW;
    canvas.height = targetH;
    if (game.renderer && typeof game.renderer.resize === 'function') {
      game.renderer.resize(targetW, targetH);
    }
  }
}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…