Matter-js: How do you properly resize canvas for responsive design? Any related API?

Created on 21 Jun 2018  路  1Comment  路  Source: liabru/matter-js

First of all, thank you for this wonderful javascript library.

I want full-screen canvas, but I didn't find any API to do this.

In Pixi.js, I can resize like this.

this.App.renderer.resize(clientWidth, clientHeight);

But right now I ended up this code

  resizeCanvasRenderer = () => {
    this.canvasRenderer.canvas.width =
      this.props.width * window.devicePixelRatio;
    this.canvasRenderer.canvas.height =
      this.props.height * window.devicePixelRatio;

    this.canvasRenderer.canvas.style.width = `${this.props.width}px`;
    this.canvasRenderer.canvas.style.height = `${this.props.height}px`;
  };

The code above seems to work.
However, this scene becomes so small. I have no idea why this is happening.
I am very new to Matter.js
Please help~~Thank you

question

Most helpful comment

This is expected with the simple built in renderer, but it looks like you just want to account for high density displays? Try using Render.setPixelRatio(renderer, 'auto').

>All comments

This is expected with the simple built in renderer, but it looks like you just want to account for high density displays? Try using Render.setPixelRatio(renderer, 'auto').

Was this page helpful?
0 / 5 - 0 ratings

Related issues

moe091 picture moe091  路  3Comments

car1ot picture car1ot  路  3Comments

kunchenguid picture kunchenguid  路  3Comments

mrspeaker picture mrspeaker  路  3Comments

TimuJiang picture TimuJiang  路  4Comments