Jump to content

Question about keys: Pressed vs. isDown


SlimTim
 Share

Recommended Posts

So, I'm looking through the keyboard docs in order to find a function for buttons being pressed as opposed to being held down. Say I'm firing a bullet, I only want one bullet spawned per button press, regardless of how long the button is held down.

 

I have achieved this with raw JavaScript earlier using a boolean:

isButtonADown = false;if(buttonA){    if(!isFiringButtonDown){        console.log("Shot fired.");        isFiringButtonDown = true;    }}else{    isFiringButtonDown = false;}

Is there anyting like this implemented in Phaser?

Link to comment
Share on other sites

  • 7 months later...

I'd say a better approach on this is:

(I like prototyping better than throwing code around)

//on create of YouGame.Game.prototype receiving game when declaredcreate: function () {//......gunfire = this.input.keyboard.addKey(Phaser.Keyboard.X);gunfire.onDown.add(this.gunfired,this);},//now the fire function after the update one:gunfired: function(key) {//fire it here//also you can attach a .name on gunfire and switch(key.name) for each type of gun.},
Link to comment
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...
 Share

  • Recently Browsing   0 members

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