i3Designer Posted September 22, 2014 Share Posted September 22, 2014 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 More sharing options...
MorpheusZ Posted September 22, 2014 Share Posted September 22, 2014 Phaser doesn't call update() when paused. Try using window.onkeydown.Something like:window.onkeydown = function(event) { if (event.keycode == 80) game.paused = true;} Link to comment Share on other sites More sharing options...
i3Designer Posted September 22, 2014 Author Share Posted September 22, 2014 I did not understand. Why keycode == 80? http://8islandlabs.com/games/wizard/phaser/docs/Keyboard.js.htmlI put in create function... Link to comment Share on other sites More sharing options...
j0hnskot Posted September 22, 2014 Share Posted September 22, 2014 80 is the keycode of the letter "P" . That's why you put 80 in there. Use thiswindow.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. Link to comment Share on other sites More sharing options...
i3Designer Posted September 22, 2014 Author Share Posted September 22, 2014 80 is the keycode of the letter "P" . That's why you put 80 in there. Use thiswindow.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") ... lol80 is right. Link to comment Share on other sites More sharing options...
j0hnskot Posted September 22, 2014 Share Posted September 22, 2014 Change event.keycode to event.keyCode . Pay attention to the capital C on keyCode. i3Designer 1 Link to comment Share on other sites More sharing options...
lewster32 Posted September 22, 2014 Share Posted September 22, 2014 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;} j0hnskot 1 Link to comment Share on other sites More sharing options...
i3Designer Posted September 22, 2014 Author Share Posted September 22, 2014 OOOOOOOOOOK i solved: window.onkeydown = function() { if (game.input.keyboard.event.keyCode == 80){ game.paused = !game.paused; } } Link to comment Share on other sites More sharing options...
i3Designer Posted September 22, 2014 Author Share Posted September 22, 2014 Thanks lewster32 j0hnskot MorpheusZ I must learn to read well the API, and I don't speak English very well. This is my website: http://www.samuelesciacca.iand this is my firs videogame but now i work to a new.http://www.cade.samuelesciacca.it Link to comment Share on other sites More sharing options...
Recommended Posts