guansss / pixi-live2d-display

A PixiJS plugin to display Live2D models of any kind.
https://guansss.github.io/pixi-live2d-display/
MIT License
823 stars 125 forks source link

How to set the model in the center of the screen? #94

Closed JMedina90 closed 1 year ago

JMedina90 commented 1 year ago

Is this possible? Also, is it possible to adjust the model to the size of the screen?

Thanks

loclink commented 1 year ago

In the PIXI application creation phase, set the attribute resizeTo to window and view to HTMLCanvasElement, after which you just need to adjust the position of the canvas in the window and keep it centered.

If you need to resize the model according to the screen, you can listen to the window.resize event or a custom media query event, and then just set the scale property of the model to scale it, for example:

  const xs = window.matchMedia('screen and (max-width: 768px)');
  xs.addEventListener('change', (e) => {
    if (e.matches)  model.scale.set(0.1);
  });
JMedina90 commented 1 year ago

In the PIXI application creation phase, set the attribute resizeTo to window and view to HTMLCanvasElement, after which you just need to adjust the position of the canvas in the window and keep it centered.

If you need to resize the model according to the screen, you can listen to the window.resize event or a custom media query event, and then just set the scale property of the model to scale it, for example:

  const xs = window.matchMedia('screen and (max-width: 768px)');
  xs.addEventListener('change', (e) => {
    if (e.matches)  model.scale.set(0.1);
  });

This is what I was looking for. Thank you!