Jump to content

Space bar listener to trigger pause screen only firing twice


Puzz3l
 Share

Recommended Posts

I have a listener on the space button the pause the game, like so:

this.space = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR);this.space.onDown.add(function() {    game.paused = !game.paused;}, this);

I press the spacebar once, it pauses the game. I press it again, it unpauses it. I press it AGAIN and it doesn't pause. Why is this happening?

 

Also; if I replace the 

game.paused = !game.paused;

with just 

console.log("Here.");

I get a log at every press, like desired. So it has something to do with the pause mid-execution of the listener. Not sure what the fix for that is, though.

Link to comment
Share on other sites

Is it possible that there is more going on in your code?

Because i just pasted your 4 lines from the post directly into the create function of my game, and space paused and unpaused the game multiple times without problems.

 

(disclaimer: the project I just checked this in is phaser 2.0 beta .. not the current 2.0.3)

Link to comment
Share on other sites

Just downloaded the dev branch, it works fine now  :rolleyes:  I'm still curious why it doesn't work with the stable, though. I haven't used the dev branch before (hell, I never used Phaser before two days ago), are there anythings that won't work in it?

Link to comment
Share on other sites

I think using dev directly is a gamble. (things might be improved, other things might be temporary broken.)

 

It also depends on if you build the phaser.js (and phaser.min.js) from the content of the dev repository, or if you use the phaser.js that is in the dev repository.

 

(For building you need nodejs and grunt - it's not hard to do, but takes at least some getting used to - i am sure there is a tutorial how to do it somewhere *g*)

 

This is because more often then not (rich and other contributors) just updates the single source files and not always the complete phaser.js.

Link to comment
Share on other sites

Cool. I have a new problem though... Here's my code now:

 

this.space.onDown.add(function() {    if(!game.paused) {        console.log('Here.');        this.g = this.game.add.graphics(208, 126);        this.g.beginFill(0xffffff, 64);        this.g.drawRect(new Phaser.Rectangle(0, 0, 720, 388));        this.g.endFill();        game.paused = true;    } else {        this.g.destroy();        game.paused = false;    }}, this);

Unfortunately the graphics is never drawn  :(

 

Wait a second I messed up, I see what I did wrong. I should be drawRect(new Phaser.Rectangle(0, 0, 720, 388))

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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