Heppell08 Posted January 19, 2014 Share Posted January 19, 2014 I'm trying to create and assign a pause to my game. I want it on the letter 'P' but for some reason it wont bind at all. I'm using the same code thats in the examples of the phaser sources and yet still it won't bind at all. I've got cursors working with the var cursors and input as create keys and even when i use that approach it wont bind to 'P'.its set like so:cursors = game.input.keyboard.createCursorKeys();if(cursors.left.isDown) { player.body.velocity.x = -150; if(facing !== 'left') { facing = 'left'; } }// they all work as standard for up/left and rightand i'm trying to do this in this:if(cursors.P.justPressed){ game.state.pause;}// not sure if the game will pause, cant bind key...Keep getting cant read property justPressed of undefined and also cannot read property of undefined P.I'm using the phaser code provided so i have got a clue what im doing wrong.I've went through this > http://gametest.mobi/phaser/docs/Phaser.Key.html#toc14too. Any help? Thanks Link to comment Share on other sites More sharing options...
XekeDeath Posted January 19, 2014 Share Posted January 19, 2014 P is not a cursor key, they are only the arrow keys.createCursorKeys() is a shortcut function that sets up the arrow keys quickly, as they are commonly used. What you want is:var pauseKey = game.input.keyboard.addKey(Phaser.Keyboard.P); jerome 1 Link to comment Share on other sites More sharing options...
Heppell08 Posted January 19, 2014 Author Share Posted January 19, 2014 Yeah I tried your method too before trying the cursor key method. I keep getting error and not being able to bind the keys. Might go through the code a bit more. I've probably over looked something. Link to comment Share on other sites More sharing options...
XekeDeath Posted January 19, 2014 Share Posted January 19, 2014 Also, justPressed is a function, not a property. in create, have:pauseKey = game.input.keyboard.addKey(Phaser.Keyboard.P);in update, you haveif ( pauseKey.justPressed(/*optional duration*/) ){ //do stuff...} kass 1 Link to comment Share on other sites More sharing options...
Heppell08 Posted January 19, 2014 Author Share Posted January 19, 2014 So if I had it set to a number say. Then set it to a pause. Then to unpause have it reset the number after a justPressed? I want it so that press to pause/unpause. That justPressed info was super helpful too! Thanks! Link to comment Share on other sites More sharing options...
XekeDeath Posted January 19, 2014 Share Posted January 19, 2014 You should probably use an onDown signal instead of justPressed.justPressed doesn't tell you if a key was pressed in the last frame, or if it just entered the pressed state, it tells you if it was pressed in the last x milliseconds...so in the update function, justPressed will return true for multiple updates, effectively pausing and unpausing your game until the key is released, or the threshhold for justPressed is reached. onDown allows you to attach callbacks to when the key is pressed, and they will fire once as the key enters the pressed state.Something like this:pauseKey.onDown.add(pauseFunction, this);pauseFunction = function(){ pause = !pause;} tijuinem 1 Link to comment Share on other sites More sharing options...
Recommended Posts