Jump to content

Creating Keyboard Keys


Heppell08
 Share

Recommended Posts

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 right

and 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#toc14

too. Any help? Thanks

Link to comment
Share on other sites

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;}
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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