How to double click in Phaser

By default Phaser allows you to perform a basic single click method, but what if we want the user to double click? Below is how we do it:

this.yourButton.events.onInputDown.add(this.confirmDoubleClick, this);

confirmDoubleClick: function(itemBeingClicked) {
if (!this.secondClick) {
this.secondClick = true;
this.time.events.add(300, function(){
this.secondClick = false;
},this);
return;
}

console.log ("Then this code gets actioned as a result of your double click.");

}

So simply replace the console log code with your code that you want to action when the double click is triggered. NOTE that I have set the double click check rate at 300 milliseconds which is a reasonable amount of time between the 2 clicks / taps, but you can alwyas change this in the code.

 

Like It? Share It!

 

Leave a comment

 

Need help with this article?

Have you got a suggestion, compliment or need additional help with this article? Simply contact me at ajfhoward[@t]hotmail.com and I'll try to help as much as I can.