Jump to content

Is there a double-click feature?


Arcanorum
 Share

Recommended Posts

Does Phaser have anything for deciding if a double-click has taken place?

 

I've found some other topics regarding double-clicking but none have had particularly useful replies IMO.

 

I've been trying to hack something together using timers and game.input.activePointer.justPressed but I feel like I'm doing it wrong.

 

Also, how does this Sprite.events.onInputDown thing work? Why is this input detection event in Sprite?

Link to comment
Share on other sites

From what I've seen of the code, there is no double click event.  However, there is an extra parameter passed into "onTap" that denotes double click:

// Was it a double-tap?if (this.timeUp - this.previousTapTime < this.game.input.doubleTapRate){  // Yes, let's dispatch the signal then with the 2nd parameter set to true  this.game.input.onTap.dispatch(this, true);

That means you can have a double click handler by doing something like:

game.input.onTap.add(function(pointer, isDoubleClick) {  if(!isDoubleClick) {    return;  }  // Handle double click.});

Then again, you could also use the native dblclick event.

Link to comment
Share on other sites

Cool, that works. Though I see that it is only considered a double click after the second click has come up.

 

I need it to activate the double click as soon as the second click is pressed, not released. What I'm trying to do is where a player clicks, then clicks again and holds down in order to move.

 

So I think I need a combination of onTap and onHold functionality.

Link to comment
Share on other sites

Ok, so I've wasted all day trying to figure out what is a really simple concept, with no success.

 

I haven't found anything in Phaser that has the functionality I require, and all of my own solutions that I think have been logically correct have for some reason not worked.

 

I have tried making my code as explicit as possible to make sure the logic is correct, and to my understanding it is.

 

Here is what I am trying in update();

    if(game.input.activePointer.justPressed(0)){        timeGap = game.time.now - lastClickTime;        if(timeGap < doubleClickDelay){            doubleClickHeld = true;        }        lastClickTime = game.time.now;    }    if(doubleClickHeld === true){        // Do this code while second click is still held.    }    // If the pointer is released, then the second click obviously can't be held down.    if(game.input.activePointer.justReleased(0)){        doubleClickHeld = false;    }

But the code to do while doubleClickHeld is still true is being read even if I press only once. Which makes me think that the first if statement is always true. Am I using justPressed wrong?

Link to comment
Share on other sites

I've built a small Gesture class that detects basic touch gestures, swipe (with swipe direction), tap, and hold. Have a look at here. Feel free to extend it. 

 

Usage:

create: {  // create a gesture instance in the state's create method.  this.gesture = new Gesture(this.game);  // add gesture handlers.  this.gesture.onSwipe(this.swipeHandler, this);  this.gesture.onHold(this.holdHandler, this);  this.gesture.onTap(this.tapHandler, this);},update: {  // call gesture's update method each frame.  this.gesture.update();},// handle gesturesswipeHandler: function(downPosition, position, direction) {},tapHandler: function(downPosition, position) {},
Link to comment
Share on other sites

  • 5 years later...
 Share

  • Recently Browsing   0 members

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