Hi all!
I’m trying to make an adaptive background for all resolutions in phaser. I was able to achieve the desired effect, but only in devtools mode. When I look at the background in a regular browser window, it gets cut off. Is there a way to bring the scale state to a single view?
The first photo is the desired behavior.
The second photo is what it looks like without devtools.
Also, i give my code for scale background.
// config
const config = {
type: Phaser.AUTO,
scene: scenes,
physics: {
default: "arcade",
arcade: {
default: false,
},
},
scale: {
width: window.innerWidth,
height: window.innerHeight,
mode: Phaser.Scale.RESIZE,
autoCenter: Phaser.Scale.CENTER_BOTH,
},
autoRound: false,
};
// method for scale background
fillBackground() {
const initialWidth = ResizeObserver.isMobile(this);
initialWidth
? this.#createBackground(this.#backgroundDesktopName)
: this.#createBackground(this.#backgroundDesktopName);
const screenWidth = this.scale.width;
const screenHeight = this.scale.height;
if (!this.#backgroundFill) return;
const scaleX = screenWidth / this.#backgroundFill.width;
const scaleY = screenHeight / this.#backgroundFill.height;
const scale = Math.max(scaleX, scaleY);
this.#backgroundFill.setScale(scale);
this.#backgroundFill.x = screenWidth / 2;
this.#backgroundFill.y = screenHeight / 2;
}
Thanks!