[英]How can I obtain screen scaling similar to Slither.io's using Phaser.js?
[英]How can user quit full screen in phaser.js?
我有一个自动全屏播放的游戏
this.scale.startFullscreen();
我想给用户一个选项,通过按右上角的“x”来退出全屏。 所以我写道:
this.add.text(750, 20, 'X', { fontSize: '20px'});
this.exitFullScreen = this.add.rectangle(770, 30, 60, 60, 0xfff);
this.exitFullScreen.setInteractive();
this.exitFullScreen.on('pointerup', this.scale.stopfullScreen);
但这不起作用,我也尝试将this.scale.stopfullScreen
放在回调 function 中,并且我还添加了条件if (isFullscreen())
,但这也不起作用。 有什么办法可以让用户选择退出全屏,最好不要删除this.scale.startFullscreen();
在create()
的开头?
问题是这一行this.exitFullScreen.on('pointerup', this.scale.stopfullScreen);
eventlistener .on('pointerup', ...)
使用不同的上下文调用传递的回调 function。
只需将事件监听器更改为.on('pointerup', () => this.scale.stopFullscreen());
它应该可以工作。
或者您可以将正确的上下文(用于函数)作为第三个参数传递给事件监听器,如下所示: .on('pointerup', this.scale.stopFullscreen, this.scale);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.