<!doctype html>
<
meta http-equiv="Content-Type" content="text/html; charset=utf-8">
html, body {
margin: 0;
}
.emscripten {
width: 100%;
height: 100%;
display: flex;
position: absolute;
align-items: center;
justify-content: center;
}
.game {
width: auto;
height: 100%;
}
.portrait{
width: 100%;
height: auto;
}
.loading {
position: absolute;
}
.game[width] + .loading {
display: none;
}
<canvas class="game portrait" oncontextmenu="event.preventDefault()"></canvas>
<
div class="loading">Loading...<
/div>
<
script type="text/javascript">
const $game = document.querySelector('.game');
const widthToHeight = 640 / 480;
const resize = () => {
if(window.innerWidth / window.innerHeight > widthToHeight === $game.classList.contains('portrait')) {
$game.classList.toggle('portrait');
}
}
var Module = {
print(text) {
console.log(Array.prototype.slice.call(arguments).join(' '));
},
printErr() {
console.error(Array.prototype.slice.call(arguments).join(' '));
},
canvas: $game
};
window.addEventListener('resize', resize, false);
resize();
// Work-around chromium autoplay policy
// https://github.com/emscripten-core/emscripten/issues/6511
function resumeAudio(e) {
if (typeof Module === 'undefined'
|| typeof Module.SDL2 == 'undefined'
|| typeof Module.SDL2.audioContext == 'undefined')
return;
if (Module.SDL2.audioContext.state == 'suspended') {
Module.SDL2.audioContext.resume();
}
if (Module.SDL2.audioContext.state == 'running') {
$game.removeEventListener('click', resumeAudio);
document.removeEventListener('keydown', resumeAudio);
}
}
$game.addEventListener('click', resumeAudio);
document.addEventListener('keydown', resumeAudio);
{{{ SCRIPT }}}