I have been coding a game for a while and I want to add the settings menu, the death menu and the victory menu. For making those menus visible, I thought about 2 different options:
1:
game_loop(){
game();
document.resume_button.onclick = function(){"paused = false"};
document.pause_button.onclick = function(){"paused = true"};
if(!paused){
//if(!document.pauseMenu.visibility = "visible"){ //just an idea to prevent unnesecessary actions
document.pauseMenu.visibility = "hidden";
//}
}else{
//if(document.pauseMenu.visibility = "hidden"){
document.pauseMenu.visibility = "visible";
//}
}
}
2:
game_loop(){
game();
document.resume_button.onclick = gameOver(0);
document.pause_button.onclick = gameOver(1);
}
gameOver(x){
switch(x){
case 0:
document.pauseMenu.visibility = "hidden";
break;
case 1:
document.pauseMenu.visibility = "visible";
}
}
the difference between both is, that the first one always checks paused
and changes the value
, pressing on a button, while the second one executes gameOver()
once, pressing on a button.
Does anyone know which one is better in perfomance and usage ( for example the first one alway does the menu if its paused while the second one only shows the menu if the button is pressed)
Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW
Comments
Post a Comment