* 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)
| 10 | * @param y - y scaling multiplier |
| 11 | */ |
| 12 | function 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 |
no test coverage detected