Sign in to follow this  

Question about keys: Pressed vs. isDown

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?

Share this post

Link to post
Share on other sites

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( for each type of gun.},

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.