Jump to content

Pause with keys


i3Designer
 Share

Recommended Posts

Update:

        if(this.p.justPressed(1) && game.paused == false){
            this.menuPausa();
            game.paused = true;
        }

 

function :

      if(this.spazio.isDown && game.paused){
            game.paused = false;
        }

 

When I press "P" the game stops , and then the function does not work . How can I do?

I have to do in the function created ?

Link to comment
Share on other sites

80 is the keycode of the letter "P" . That's why you put 80 in there.

 

Use this

window.onkeydown = function(event) {  if (event.keyCode == 80){       game.paused = !game.paused;   } }

This will pause or unpause the game when P is pressed.

 

 

Edit: fixed a typo.

 

OK i Know, but i put in this:

        window.onkeydown = function(event) {
            console.log("OK")
            if (event.keycode == 80){
console.log("P");
                game.paused = !game.paused;
            }
        }

 

console.log("OK") I see it in the console,

if P.isDown does not work, because i don't see the console.log("P") ... lol

80 is right.

Link to comment
Share on other sites

It could be event.which if using Firefox too, so a cross-browser solution is as follows:

var keycode = event.keyCode || event.which;

Also, Phaser.Keyboard has consts for the keycodes so you don't have to remember them, so you can check against those:

if (keycode === Phaser.Keyboard.P) {  game.paused = !game.paused;}
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...