i3Designer

Pause with keys

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 ?

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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;}

Share this post


Link to post
Share on other sites

OOOOOOOOOOK i solved:

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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.