Arcanorum

Is there a double-click feature?

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?

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
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?

Share this post


Link to post
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) {},

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.