简体   繁体   English

如何使用 onclick 事件实现 go 全屏 - Phaser3

[英]How to go fullscreen with an onclick event - Phaser3

Hi would like to know if we can go "real" fullscreen with a click event on a Phaser3 game.您好想知道我们是否可以 go 在 Phaser3 游戏上通过点击事件“真实”全屏。 I tried so many things and nothing work.我尝试了很多东西,但没有任何效果。 I have an object and i would like to click on it to put the game on a fullscreen mode.我有一个 object,我想单击它以将游戏置于全屏模式。 Hope someone had this problem before and can help me.希望有人以前遇到过这个问题并且可以帮助我。

Config of game:游戏配置:

 const config = { parent: "game", width: 750, height: 500, type: Phaser.AUTO, zoom: 1, scene: [Loading, Menu, InGame, GameOver, Controls, Win], backgroundColor: "#ffffff", audio: { disableWebAudio: true, noAudio: false }, physics: { default: "arcade", arcade: { gravity: { y: 1500, x: 0 }, debug: false }, }, }
window.onload = function() {
    var game = new Phaser.Game(config);
}

Object click event on scenes: Object 场景点击事件:

 this.fullScreenButton = this.add.image(730, 20, "fullScreen"); this.fullScreenButton.setInteractive(); this.fullScreenButton.on('pointerdown', function() { this.scene.scale.setGameSize(window.innerWidth, window.innerHeight); this.scale.startFullscreen(); });
let fullscreen = this.add.image(16,16,'fullscreen').setInteractive();

fullscreen.on('pointerup',() => { 
  window['game']['canvas'][game.device.fullscreen.request]();
})

I had the same issue and don't know why but pointerdown has some problems with full screen mode.我有同样的问题,不知道为什么,但是pointerdown在全屏模式下有一些问题。 If you just switch to pointerup the canvas will fit the whole screen.如果您只是切换到指针向上 canvas 将适合整个屏幕。

Hope this can be helpful.希望这会有所帮助。 Ab抗体

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM