Fixed flickering after pause

This commit is contained in:
Garrett Finucane 2014-07-02 11:10:36 -04:00
parent 4090f36b83
commit 3764ececd8
4 changed files with 50 additions and 47 deletions

View file

@ -1,46 +1,3 @@
var prevGameState;
function showText(text){
var messages = {
'paused':"<div class='centeredHeader unselectable'>Paused</div><br><div class='unselectable centeredSubHeader'>Press p to resume</div>",
'start':"<div class='centeredHeader unselectable' style='line-height:80px;' >Press enter to start</div>",
'gameover':"<div class='centeredHeader unselectable'> Game Over: "+score+" pts</div><br><table class='tg' style='margin:0px auto'> <tr> <th class='tg-031e'>1.</th> <th class='tg-031e'>"+highscores[0]+"</th> </tr> <tr> <td class='tg-031e'>2.</td> <th class='tg-031e'>"+highscores[1]+"</th> </tr> <tr> <td class='tg-031e'>3.</td> <th class='tg-031e'>"+highscores[2]+"</th> </tr> </table><br><div class='unselectable centeredSubHeader'>Press enter to restart</div>",
};
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() {

View file

@ -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();

View file

@ -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':"<div class='centeredHeader unselectable'>Paused</div><br><div class='unselectable centeredSubHeader'>Press p to resume</div>",
'start':"<div class='centeredHeader unselectable' style='line-height:80px;' >Press enter to start</div>",
'gameover':"<div class='centeredHeader unselectable'> Game Over: "+score+" pts</div><br><table class='tg' style='margin:0px auto'> <tr> <th class='tg-031e'>1.</th> <th class='tg-031e'>"+highscores[0]+"</th> </tr> <tr> <td class='tg-031e'>2.</td> <th class='tg-031e'>"+highscores[1]+"</th> </tr> <tr> <td class='tg-031e'>3.</td> <th class='tg-031e'>"+highscores[2]+"</th> </tr> </table><br><div class='unselectable centeredSubHeader'>Press enter to restart</div>",
};
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;
}
}

View file

@ -116,6 +116,10 @@ button:focus {
opacity:0;
}
.unfaded {
opacity:1;
}
.centeredHeader {
font-size:5em;
text-align:center;