T
T
Tiyzz2017-11-10 07:28:13
JavaScript
Tiyzz, 2017-11-10 07:28:13

How to pause a game in javascript?

How to develop a pause in the game? It is necessary that the pause is pressed on the spacebar and after it the entire gameplay stops

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Arman, 2017-11-10
@Arik

alert(), confirm() =)

E
Exploding, 2017-11-10
@Exploding

Purely theoretically, if you assume a lot of things, then maybe so?

$(document).on("keydown", function(e){
  if(e.keyCode == 27) {
    var gPause = myGame.currentStatus("isPaused");
    var frozenData = {};
    
    if(!gPause){
      myGame.gameCurrentProcessing.all("stop").currentStatus("paused", true);
      frozenData = myGame.detach();
    } else {
      frozenData.appendTo(document.body);
      myGame.gameCurrentProcessing.all("start").currentStatus("paused", false);
    }		
  }
  
});

Presumably the myGame object is a jq-plugin, and if not, it's okay, one edit and the rules: "$(myGame).detach();"
The names of the methods, as well as their existence, are taken from the ceiling, so replace them with your own.
Although.... what am I talking about...

V
V Sh., 2017-11-10
@JuniorNoobie

function tickOfGame() {
  if (!paused) nextStep();
}

D
Dmitry Alexandrov, 2017-11-10
@jamakasi666

Elementrano. To begin with, it is necessary that there is no shitty code and there are clear demarcations in the game where the logic calculation, rendering, etc. takes place. For a pause, you simply stop calculating the logic, leaving everything else, i.e. the world will freeze but will render correctly, in the same way the freeze time is done like everything is frozen and you can fly the camera and evaluate everything.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question