带有 autoCenter 的 Phaser.js 将偏移画布边界矩形

问题描述

我正在尝试使用 Phasers scale-manager 来让它像 felgo 的 文章create mobile games for different screen sizes 中那样响应更快。如果有人知道如何在 Phaser 中做到这一点,请分享

当我将游戏配置设置为 autoCenter: Phaser.Scale.CENTER_BOTH 然后在场景中我测试了边界,我发现它们在宽度和高度两个方向都有偏移,如何将其居中。

这是正在休息的游戏代码

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);
})

和场景代码

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);
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)