Jump to content

how to detect double tap


markjsb
 Share

Recommended Posts

  • 3 weeks later...

I've ended up with the idea of starting a small timer on the first tap and if a second is not received within a given time then calling a single tap callback otherwise calling a double tap callback.

 

The problem is that if you don't wait to see if there is a second that every double tap also being classed as a single.  In my case it is single tap to move to a position double tap to attack a position  - which would have had the effect moving squishies to melee range on every attack. wooops.

 

haven't written it yet so no example code.

Link to comment
Share on other sites

But that is a problem that will never really go away.

You can't know if another tap is coming or not.

 

The same applies to click and double-click.

 

Windows for example uses a defined amount of time (which you can change in the mouse settings) between clicks to determine if it's two single clicks or a double click.

 

Btw: you do not need to start any timer, you just create a variable in which you store game.time.now - and then on the second click you compare game.time.now to the content of that variable. (the difference is the time between the clicks)

 

Workaround:

You could start a timer on single click (that fires shortly after the double-tap-amount-of-time) and kill that timer if the second tap comes in time.

 

This way you have either a (slightly delayed) single tap event, or the double tap event.

Link to comment
Share on other sites

Typescript example:

        dClickLast: number;        isDoubleClick(o_pointer: Phaser.Pointer) : boolean {            if (o_pointer.justReleased(30)) {                var now = new Date().getTime();                var timesince = now - this.dClickLast;                if((timesince < 600) && (timesince > 0)) {                    return true;                }                this.dClickLast = new Date().getTime();            }            return false;        }
Link to comment
Share on other sites

  • 1 year later...

This is my solution :

var mylatesttap; sprite.events.onInputDown.add(doubleclick,this); function doubleclick(item,pointer){    var now = new Date().getTime();   var timesince = now - mylatesttap;    if((timesince < 600) && (timesince > 0)){     console.log("double tap");   }else{    console.log("don't");   }    mylatesttap = new Date().getTime();}
Link to comment
Share on other sites

  • 1 year later...

Of note, here's a solution for double tapping on a specific sprite

var tapHandler = function(sprite, pointer) {
 if (pointer.msSinceLastClick < game.input.doubleTapRate) {
      console.log('Double clicked sprite: ', sprite.key);
  }
};

//

var create = function(game) {
  // Create sprite
  var myFancySprite = game.add.sprite(10, 10, 'fancyspritekey');

  // enable input
  myFancySprite.inputEnabled = true;

  // add event listener
  myFancySprite.events.onInputDown.add(tapHandler, this);
};


 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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