JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/2.6.1/phaser.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/phaser/2.6.2/phaser.js"></script>
<button id=request>document.body.requestFullscreen()</button>
<button id=exit>document.exitFullscreen()</button>
JavaScript
const scaleKeys = ['fullScreenScaleMode', 'fullScreenTarget', 'hasPhaserSetFullScreen', 'isFullScreen'].sort();
const docKeys = ['fullscreenEnabled', 'fullscreenElement'].sort();
const $request = document.getElementById('request');
const $exit = document.getElementById('exit');
if (document.body.requestFullscreen) $request.addEventListener('click', document.body.requestFullscreen);
else $request.disabled = true;
if (document.exitFullscreen) $exit.addEventListener('click', document.exitFullscreen);
else $exit.disabled = true;
var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', {
init: init,
create: create,
update: update,
render: render
});
function onFullScreenChange(scale) {
console.log('Fullscreen mode changed to ' + scale.isFullScreen);
}
function onFullScreenError(scale) {
console.error('Failed to enter fullscreen :(');
}
var targetElement;
function onFullScreenInit(scale, args) {
targetElement = args.targetElement;
console.log('Requesting fullscreen mode for', targetElement);
}
function init() {
game.debug.font = '24px monospace';
game.debug.lineHeight = 40;
game.scale.onFullScreenChange.add(onFullScreenChange);
game.scale.onFullScreenError.add(onFullScreenError);
game.scale.onFullScreenInit.add(onFullScreenInit);
}
function create() {
var font = '64px sans-serif';
game.add.button(20, 50, null, game.scale.startFullScreen, game.scale).addChild(
game.make.text(0, 0, 'startFullScreen', {
fill: '#7FDBFF',
font: font
})
);
game.add.button(20, 150, null, game.scale.stopFullScreen, game.scale).addChild(
game.make.text(0, 0, 'stopFullScreen', {
fill: '#FFDC00',
font: font
})
);
}
function update() {}
function render() {
var debug = game.debug;
debug.start(20, 300);
for (const key of scaleKeys) {
debug.line('game.scale.' + key + ': ' + game.scale[key]);
}
for (const key of docKeys) {
debug.line('document.' + key + ': ' + document[key]);
}
...