so://phie

game-engine

A lightweight JavaScript game engine
git clone git://soophie.de/game-engine

blob: 7b5717a736f4871c1853691c5b3ea4758611795c (600 bytes)[doc][blame][raw]

1const DEVICE_PIXEL_RATIO = window.devicePixelRatio || 1;

2

3export function scaleCanvas(canvas, width, height) {

4 const g = canvas.getContext('2d');

5 const backingStoreRatio = g.webkitBackingStorePixelRatio || 1;

6 const ratio = DEVICE_PIXEL_RATIO / backingStoreRatio;

7 if(DEVICE_PIXEL_RATIO != backingStoreRatio) {

8 canvas.width = width * ratio;

9 canvas.height = height * ratio;

10 canvas.style.width = width + 'px';

11 canvas.style.height = height + 'px';

12 }

13 else {

14 canvas.width = width;

15 canvas.height = height;

16 canvas.style.width = '';

17 canvas.style.height = '';

18 }

19 g.scale(ratio, ratio);

20}