[英]How to go fullscreen with an onclick event - Phaser3
您好想知道我們是否可以 go 在 Phaser3 游戲上通過點擊事件“真實”全屏。 我嘗試了很多東西,但沒有任何效果。 我有一個 object,我想單擊它以將游戲置於全屏模式。 希望有人以前遇到過這個問題並且可以幫助我。
游戲配置:
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 場景點擊事件:
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]();
})
我有同樣的問題,不知道為什么,但是pointerdown在全屏模式下有一些問題。 如果您只是切換到指針向上 canvas 將適合整個屏幕。
希望這會有所幫助。 抗體
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.