MCPcopy Create free account
hub / github.com/melonjs/melonJS / scale

Function scale

packages/melonjs/src/application/resize.ts:12–34  ·  view source on GitHub ↗

* scale the "displayed" canvas by the given scalar. * this will modify the size of canvas element directly. * Only use this if you are not using the automatic scaling feature. * @param game - the game application instance triggering the resize * @param x - x scaling multiplier * @param y - y sc

(game: Application, x: number, y: number)

Source from the content-addressed store, hash-verified

10 * @param y - y scaling multiplier
11 */
12function scale(game: Application, x: number, y: number): void {
13 const renderer = game.renderer;
14 const canvas = renderer.getCanvas();
15 const settings = renderer.settings as any;
16 const pixelRatio = device.devicePixelRatio;
17
18 const w = (settings.zoomX = canvas.width * x * pixelRatio);
19 const h = (settings.zoomY = canvas.height * y * pixelRatio);
20
21 // update the global scale variable
22 renderer.scaleRatio.set(x * pixelRatio, y * pixelRatio);
23
24 // adjust CSS style based on device pixel ratio
25 canvas.style.width = `${w / pixelRatio}px`;
26 canvas.style.height = `${h / pixelRatio}px`;
27
28 // if anti-alias and blend mode were reset (e.g. Canvas mode)
29 renderer.setAntiAlias(settings.antiAlias);
30 renderer.setBlendMode(settings.blendMode);
31
32 // force repaint
33 game.repaint();
34}
35
36/**
37 * callback for window resize event

Callers 1

onresizeFunction · 0.70

Calls 5

getCanvasMethod · 0.80
repaintMethod · 0.80
setMethod · 0.45
setAntiAliasMethod · 0.45
setBlendModeMethod · 0.45

Tested by

no test coverage detected