Phaser 3 ScaleManager异常

问题描述

我试图在用Phaser 3编写的游戏中启用全屏显示。 我正在Scene类中通过

this.game.scale.startFullScreen();

但是在f12浏览器控制台中出现错误

Uncaught TypeError: this.game.scale.startFullScreen is not a function
    at TitleScene.<anonymous> (TitleScene.js:23)
    at InputPlugin.emit (phaser.js:2025)
    at InputPlugin.processDownEvents (phaser.js:167273)
    ...

docs ScaleManager类中有startFullScreen方法。

为什么控制台告诉我没有?


这是TitleScene.js的完整代码:

export class TitleScene extends Phaser.Scene {

    constructor ()
    {
        const config =
        {
            key: 'TitleScene'
        }
        super(config);
    }

    preload ()
    {
        this.load.image('Title','assets/Title.png');
    }

    create ()
    {
        this.background = this.add.image(960,540,'Title');
        this.input.manager.enabled = true;
        this.input.once('pointerdown',function () {
            this.scene.start('MainScene');
            this.game.scale.startFullScreen();  // here is the error
        },this);
    }

}

解决方法

有两个问题使我无法解决此问题:

  1. 我遵循了此处的示例

    https://www.phaser.io/examples/v2

    但是我正在使用第三个版本的Phaser。每个使用相同代码的人都必须遵循此处的示例

    https://www.phaser.io/examples/v3

    在使用带有示例的网站时,您必须注意url。乍看之下,两个页面都是相同的。但是网址不同。在每个使用第二(旧)版本引擎的示例之后也将发出警告。

  2. 最后,该函数名称不是startFullScreen而是startFullscreen:)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...