Warning: The magic method EDD_Blocks::__wakeup() must have public visibility in /home/wcc1969/public_html/phasergames.com/wp-content/plugins/edd-blocks-master/edd-blocks.php on line 101

Warning: The magic method EDD_Blocks::__wakeup() must have public visibility in /home/wcc1969/public_html/phasergames.com/wp-content/plugins/edd-blocks/edd-blocks.php on line 101

Warning: The magic method GAINWP_Manager::__wakeup() must have public visibility in /home/wcc1969/public_html/phasergames.com/wp-content/plugins/ga-in/gainwp.php on line 78

Deprecated: Optional parameter $filter declared before required parameter $metric is implicitly treated as a required parameter in /home/wcc1969/public_html/phasergames.com/wp-content/plugins/ga-in/tools/gapi.php on line 555

Deprecated: Optional parameter $filter declared before required parameter $metric is implicitly treated as a required parameter in /home/wcc1969/public_html/phasergames.com/wp-content/plugins/ga-in/tools/gapi.php on line 585

Deprecated: Optional parameter $filter declared before required parameter $metric is implicitly treated as a required parameter in /home/wcc1969/public_html/phasergames.com/wp-content/plugins/ga-in/tools/gapi.php on line 617

Deprecated: Optional parameter $filter declared before required parameter $metric is implicitly treated as a required parameter in /home/wcc1969/public_html/phasergames.com/wp-content/plugins/ga-in/tools/gapi.php on line 651

Deprecated: Optional parameter $filter declared before required parameter $metric is implicitly treated as a required parameter in /home/wcc1969/public_html/phasergames.com/wp-content/plugins/ga-in/tools/gapi.php on line 686

Deprecated: Optional parameter $filter declared before required parameter $metric is implicitly treated as a required parameter in /home/wcc1969/public_html/phasergames.com/wp-content/plugins/ga-in/tools/gapi.php on line 745

Deprecated: Optional parameter $filter declared before required parameter $metric is implicitly treated as a required parameter in /home/wcc1969/public_html/phasergames.com/wp-content/plugins/ga-in/tools/gapi.php on line 785
How to Double Click in Phaser 3 - Phaser Games

How to Double Click in Phaser 3

One of the things missing from a lot of modern frameworks is the ability to detect a double click. When you come down to it, a double click is simply 2 single clicks close together. All we really need to do is measure the time between clicks. We can do that by measuring the delta time.

class SceneMain extends Phaser.Scene {
    constructor() {
        super('SceneMain');
    }
    preload() {}
    create() {
        this.firstClickTime = 0;
        //add a listeners for when the pointer goes down
        this.input.on('pointerdown', this.onDown.bind(this));
    }
    getTime() {
        //make a new date object
        let d = new Date();
        //return the number of milliseconds since 1 January 1970 00:00:00.
        return d.getTime();
    }
    onDown() {
        //if the firstClickTime is 0 then
        //this we record the time and leave the function
        if (this.firstClickTime == 0) {
            this.firstClickTime = this.getTime();
            return;
        }
        //
        //get the elapsed time between clicks
        //
        let elapsed = this.getTime() - this.firstClickTime;
        //
        //if the time between clicks is less than 350 milliseconds
        //it is a doulble click
        //
        if (elapsed < 350) {
            console.log("double click");
        }
        //
        //reset the firstClickTime
        //
        this.firstClickTime = 0;
    }
    update() {}
}

Leave a Comment