Jump to content

resize window


Recommended Posts

Hi! I need help, I need it when the screen is rotated, all the children have kept their size, but the background has been adjusted to the screen size. 

Screenshot_26.png.ef2a9da17b63e848b25cec60ba86bc22.pngScreenshot_25.thumb.png.91bc66c0811f2b24f2a9cd30abe885f9.png

 

I have code

let app = new PIXI.Application({ 
	width: window.innerWidth, 
	height: window.innerHeight,
	autoResize: true,
	resolution: devicePixelRatio 
});
document.body.appendChild(app.view);
function resize() {

	app.view.style.width = window.innerWidth + 'px';
	app.view.style.height = window.innerHeight + 'px';

}

window.onresize = resize;

The last figure shows what is happening now.

Screenshot_27.png

Link to post
Share on other sites

what about

 

//this is the class _app extends PIXI.Application

document.body.onresize = () => { this.scaleToWindow() };

    scaleToWindow() {
        const canvas = this.view; // PIXI.Application.view
        let scaleX, scaleY, scale, center;
        scaleX = window.innerWidth / canvas.offsetWidth;
        scaleY = window.innerHeight / canvas.offsetHeight;
        scale = Math.min(scaleX, scaleY);
        canvas.style.transformOrigin = "0 0";
        canvas.style.transform = "scale(" + scale + ")";
        if (canvas.offsetWidth > canvas.offsetHeight) {
        if (canvas.offsetWidth * scale < window.innerWidth) { center = "horizontally" }
        else { center = "vertically" };
        } else {
        if (canvas.offsetHeight * scale < window.innerHeight) { center = "vertically" }
        else { center = "horizontally"; };
        };
        let margin;
        if (center === "horizontally") {
            margin = (window.innerWidth - canvas.offsetWidth * scale) / 2;
            canvas.style .marginTop = 0 + "px";canvas.style .marginBottom = 0 + "px";
            canvas.style .marginLeft = margin + "px";canvas.style .marginRight = margin + "px";
        };
        if (center === "vertically") {
            margin = (window.innerHeight - canvas.offsetHeight * scale) / 2;
            canvas.style .marginTop  = margin + "px";canvas.style .marginBottom = margin + "px";
            canvas.style .marginLeft = 0      + "px";canvas.style .marginRight  = 0      + "px";
        };
        canvas.style.paddingLeft = 0 + "px";canvas.style.paddingRight  = 0 + "px";
        canvas.style.paddingTop  = 0 + "px";canvas.style.paddingBottom = 0 + "px";
        canvas.style.display = "-webkit-inline-box";
        return scale;
    }; 

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...