From 3764ececd860c3a03e11acddc668504c939855c4 Mon Sep 17 00:00:00 2001 From: Garrett Finucane Date: Wed, 2 Jul 2014 11:10:36 -0400 Subject: [PATCH] Fixed flickering after pause --- js/input.js | 43 ------------------------------------------- js/render.js | 4 +--- js/view.js | 46 +++++++++++++++++++++++++++++++++++++++++++++- style/style.css | 4 ++++ 4 files changed, 50 insertions(+), 47 deletions(-) diff --git a/js/input.js b/js/input.js index e32d81c..a2fa585 100644 --- a/js/input.js +++ b/js/input.js @@ -1,46 +1,3 @@ -var prevGameState; -function showText(text){ - var messages = { - 'paused':"
Paused

Press p to resume
", - 'start':"
Press enter to start
", - 'gameover':"
Game Over: "+score+" pts

1. "+highscores[0]+"
2. "+highscores[1]+"
3. "+highscores[2]+"

Press enter to restart
", - }; - - var pt = document.getElementById("overlay"); - pt.className = ''; - pt.innerHTML = messages[text]; -} - -function hideText(text){ - var pt = document.getElementById("overlay"); - pt.className = 'faded'; - pt.innerHTML = ''; -} -function gameOverDisplay(){ - var c = document.getElementById("canvas"); - c.className = "blur"; - showText('gameover'); -} - -function pause(x,o,message) { - message = 'paused'; - var c = document.getElementById("canvas"); - if (gameState == -1 ) { - hideText(); - c.className = ''; - setTimeout(function(){ - gameState = prevGameState; - }, 300); - - } - else if(gameState != -2 && gameState !== 0 && gameState !== 2) { - c.className = "blur"; - showText(message); - prevGameState = gameState; - gameState = -1; - } -} - keypress.register_combo({ keys: "left", on_keydown: function() { diff --git a/js/render.js b/js/render.js index cb65a9e..8598185 100644 --- a/js/render.js +++ b/js/render.js @@ -32,9 +32,7 @@ function render() { } MainClock.draw(); - if (gameState ==1 || gameState ==-1 || gameState === 0) { - drawScoreboard(); - } + drawScoreboard(); for (i = 0; i < MainClock.texts.length; i++) { var alive = MainClock.texts[i].draw(); diff --git a/js/view.js b/js/view.js index eebd503..880b09d 100644 --- a/js/view.js +++ b/js/view.js @@ -64,7 +64,7 @@ function drawScoreboard() { renderText(trueCanvas.width/2+ gdx + 6 * settings.scale, trueCanvas.height/2+ gdy - 170 * settings.scale, 150, "#2c3e50", "Hextris"); renderText(trueCanvas.width/2+ gdx + 5 * settings.scale, trueCanvas.height/2+ gdy + 100 * settings.scale, 20, "rgb(44,62,80)", 'Play!'); } - else if(gameState==1 && textOpacity>=0){ + else if(gameState!=0 && textOpacity>0){ textOpacity -= 0.05; renderText(trueCanvas.width/2+ gdx + 6 * settings.scale, trueCanvas.height/2+ gdy, 60, "rgb(236, 240, 241)", String.fromCharCode("0xf04b"), 'px FontAwesome'); renderText(trueCanvas.width/2+ gdx + 6 * settings.scale, trueCanvas.height/2+ gdy - 170 * settings.scale, 150, "#2c3e50", "Hextris"); @@ -126,3 +126,47 @@ function toggleClass(element, active) { $(element).addClass(active); } } +var prevGameState; +function showText(text){ + var messages = { + 'paused':"
Paused

Press p to resume
", + 'start':"
Press enter to start
", + 'gameover':"
Game Over: "+score+" pts

1. "+highscores[0]+"
2. "+highscores[1]+"
3. "+highscores[2]+"

Press enter to restart
", + }; + + var pt = document.getElementById("overlay"); + pt.className = 'unfaded'; + pt.innerHTML = messages[text]; +} + +function hideText(text){ + var pt = document.getElementById("overlay"); + pt.className = 'faded'; + pt.innerHTML = ''; +} +function gameOverDisplay(){ + var c = document.getElementById("canvas"); + c.className = "blur"; + showText('gameover'); +} + +function pause(x,o,message) { + message = 'paused'; + var c = document.getElementById("canvas"); + if (gameState == -1 ) { + hideText(); + c.className = ''; + setTimeout(function(){ + gameState = prevGameState; + }, 300); + + } + else if(gameState != -2 && gameState !== 0 && gameState !== 2) { + c.className = "blur"; + showText(message); + prevGameState = gameState; + gameState = -1; + } +} + + diff --git a/style/style.css b/style/style.css index 52ac9fe..e65ddea 100644 --- a/style/style.css +++ b/style/style.css @@ -116,6 +116,10 @@ button:focus { opacity:0; } +.unfaded { + opacity:1; +} + .centeredHeader { font-size:5em; text-align:center;