3d-dice/dice-box

Resizing browser causes dice to not appear

Closed this issue · 4 comments

If you hide the canvas by using hide() and then resize the browser the world is resized with width and height 0 because of 'display: none'.

This can be fixed by resizing the world after calling .show()

We fixed this on our local fork by doing this:

  resizeWorld(resize) {
    this.#DiceWorld.resize(resize);
    this.#DicePhysics.postMessage({
      action: "resize",
      ...resize,
    });
  }
  show() {
    this.canvas.style.display = "block";
    this.resizeWorld({
      width: this.canvas.clientWidth,
      height: this.canvas.clientHeight,
    });
    // make this method chainable
    return this;
  }

You should be able to just update show() with the resizeWorld call then it will fix the dice disappearing on resize.

Just wanted to bump this, as this issue is still present and a fairly critical bug.

Yes especial on mobile devices this issue is a bummer.