From 04304fefef7ff34c73500efe16610e5c412fcfb5 Mon Sep 17 00:00:00 2001 From: MegaBrutal Date: Mon, 18 Apr 2016 13:53:34 +0000 Subject: [PATCH] Prevent default browser action for SPACEBAR and ARROW keys SPACEBAR scrolls the page down on some browsers, and ARROW keys may also cause the page to scroll. Now the game prevents the browser from performing these default actions when the game is in focus. Also, I removed an unused optional parameter from putText, because Internet Explorer was complaining about it. The game still doesn't work with IE though, because SVGs are not displayed. modified: shapeshift.js --- shapeshift.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/shapeshift.js b/shapeshift.js index ed05a37..e59f65c 100644 --- a/shapeshift.js +++ b/shapeshift.js @@ -57,6 +57,13 @@ [ { actor: 'guard', text: "(By the way, this is the end of the game.\nYou really can't do anything more.\nThanks for playing!)" } ]; + window.addEventListener("keydown", function(e) { + // Prevent default browser action for arrows and spacebar + if([32, 37, 38, 39, 40].indexOf(e.keyCode) > -1) { + e.preventDefault(); + } + }, false); + function sign(n) { if (n >= 0) { return 1 } else { return -1 }; } @@ -229,8 +236,8 @@ } - function putText(entity, text, color = '#000000') { - var textObject = game.add.text(entity.x, entity.y - (entity.height / 2) - 30, text, { align: 'center', fill: color, fontSize: 14 }); + function putText(entity, text) { + var textObject = game.add.text(entity.x, entity.y - (entity.height / 2) - 30, text, { align: 'center', fontSize: 14 }); textObject.font = 'Ubuntu Mono'; textObject.anchor.setTo(.5,.5); return textObject; -- 2.34.1