如何解决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);
}
}
解决方法
有两个问题使我无法解决此问题:
-
我遵循了此处的示例
https://www.phaser.io/examples/v2
但是我正在使用第三个版本的Phaser。每个使用相同代码的人都必须遵循此处的示例
https://www.phaser.io/examples/v3
在使用带有示例的网站时,您必须注意url。乍看之下,两个页面都是相同的。但是网址不同。在每个使用第二(旧)版本引擎的示例之后也将发出警告。
-
最后,该函数名称不是
startFullScreen
而是startFullscreen
:)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。