Added fullscreen API|

This commit is contained in:
Nathan Kunicki 2016-03-08 17:49:38 -06:00
parent 68e205216f
commit 483ea7cc54
4 changed files with 49 additions and 1 deletions

View File

@ -3,6 +3,19 @@
<head> <head>
<title>Pong - MomentumEngine</title> <title>Pong - MomentumEngine</title>
<script type="application/javascript" src="./dist/pong.js"></script> <script type="application/javascript" src="./dist/pong.js"></script>
<style>
#canvas:-webkit-full-screen {
width: 100% !important;
height: 100% !important;
}
#canvas:fullscreen {
width: 100% !important;
height: 100% !important;
}
</style>
</head> </head>
<body> <body>
<canvas id="canvas"></canvas> <canvas id="canvas"></canvas>

View File

@ -318,4 +318,11 @@ window.onload = function () {
pong.start(); pong.start();
document.addEventListener("keydown", function(e) {
if (e.keyCode == 13) {
pong.toggleFullScreen();
}
}, false);
}; };

View File

@ -1,6 +1,6 @@
{ {
"name": "momentumengine", "name": "momentumengine",
"version": "0.3.0", "version": "0.4.0",
"description": "An ES6 game and animation engine.", "description": "An ES6 game and animation engine.",
"main": "src/es6.js", "main": "src/es6.js",
"repository": { "repository": {

View File

@ -205,6 +205,34 @@ class Game extends Entity {
} }
toggleFullScreen () {
if (!document.mozFullScreen && !document.webkitFullScreen) {
if (this.canvas.mozRequestFullScreen) {
this.canvas.mozRequestFullScreen();
} else {
this.canvas.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
}
} else {
if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else {
document.webkitCancelFullScreen();
}
}
}
get isFullScreen () {
return (!document.mozFullScreen && !document.webkitFullScreen);
}
} }