melonjs / melonJS

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

canvas is weirdly resized upon window resize #1231

Open hornta opened 5 months ago

hornta commented 5 months 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 months ago

can i work on this issue?

obiot commented 4 months ago

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

obiot commented 4 months 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 4 months 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 4 months ago

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

TheThinker277 commented 1 month ago

@obiot Hi, Is this issue still open? I would like to work on this.

obiot commented 1 month ago

yes please ! thank you 🙇