Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
131 views
in Technique[技术] by (71.8m points)

javascript - Phaser.js with autoCenter will offset canvas bounding rectangle

Am trying figure Phasers scale-manager to get it to be more responsive like in felgo's article create mobile games for different screen sizes .If anyone knows how to do this in Phaser please do share

When I set game config to autoCenter: Phaser.Scale.CENTER_BOTH then in the scene i test the bounds I find them to have offset in both direction width and height how to center it back.

Here is the Game code am resting

const config: Phaser.Types.Core.GameConfig = {
    type: Phaser.AUTO,
    backgroundColor: '#a39b9b',
    scale: {
        parent: 'game',
        expandParent: true,
        autoCenter: Phaser.Scale.CENTER_BOTH,
        width: screenDims.gameWidth,
        height: screenDims.gameHeight,
        mode: Phaser.Scale.FIT    
    },
    scene: [PreloadScene, MainScene],
    physics: {
        default: 'arcade',
        arcade: {
            debug: false,
            gravity: {y: 400}
        }
    }
}

window.addEventListener('load', () => {
    new Phaser.Game(config);
})

and code for the scene

export default class MainScene extends Phaser.Scene {
    update() {
        this.graphics.clear();
     
        const rec = this.scale.canvasBounds;
        this.graphics.lineStyle(3, 0xffff00);
        this.graphics.strokeRectShape( rec);
    }
}
question from:https://stackoverflow.com/questions/65895579/phaser-js-with-autocenter-will-offset-canvas-bounding-rectangle

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...