melonjs / melonJS

a fresh, modern & lightweight HTML5 game engine
https://melonjs.org
MIT License
5.77k stars 641 forks source link

canvas is weirdly resized upon window resize #1231

Open hornta opened 1 week ago

hornta commented 1 week ago

The canvas is weirdly resized upon resizing the browser window. I noticed it when I alt+tabbed between my IDE and the browser, the canvas slowly get larger.

import { Text, device, game, video } from 'melonjs';

device.onReady(function () {
  // initialize the display canvas once the device/browser is ready
  if (!video.init(100, 30, {parent : "screen", scale : "auto"})) {
      alert("Your browser does not support HTML5 canvas.");
      return;
  }

  // set a gray background color
  game.world.backgroundColor.parseCSS("#202020");

  // add a font text display object
  game.world.addChild(new Text(609, 281, {
      font: "Arial",
      size: 160,
      fillStyle: "#FFFFFF",
      textBaseline : "middle",
      textAlign : "center",
      text : "Hello World !"
  }));
});

9db458ca-162c-47db-acd3-f766e4c1ddcc

KUNDAN1334 commented 4 days ago

can i work on this issue?

obiot commented 4 days ago

Please yes, sorry i was distracted with our other discussion and forgot about this one

obiot commented 4 days ago

To be noted that the same behavior appears when showing the developer tools within the browser. Since it does not happened in other cases, it never really bothered me.

obiot commented 3 days ago

@KUNDAN1334 just a heads up, in case you haven't started yet, we just pushed some big changes on the build process ! make sure to update your repo first before starting any changes. Sorry about that ! :P

KUNDAN1334 commented 2 days ago

Thanks for the heads up! I will update my local repo with the latest changes before starting on the issue. Appreciate the information!