Jump to content

pointer event for double-tap on a mesh


ozRocker
 Share

Recommended Posts

Does anyone know how to use pointer events to detect double-tap and double-click?  I'm using the pep.js framework and can't see anything in there.  Basically I just want to be able to double-tap my meshes on the screen to select them.  The dblClick event runs beautifully on desktop but unfortunately there is no equivalent for mobile devices.  I realise I could write my own with a timer but I was hoping to make my code a lot cleaner by using a single event.

Link to comment
Share on other sites

Hi ozRocker,

i don't believe such a event exists, i have never seen it anyhow.

but here's one rather easy way of doing it without being too messy :)

I haven't tested it, so it'll probably need a little bit tweaking to the timing, etc,

but it should work just fine, and if you're using 2.5 alpha you'll need to use the "new" way to handle pointer events^^

var leftClicks = 0;


scene.onPointerDown = function(evt /*, pickResult*/ ) {
  if (!scene.isReady()) return;

  if (evt.button === 0) {
    var noDoubles  = function() {
        leftClicks = 0
      },
      tOut;
    return function() {
      //if no left clicks are made within 100ms of the previous click, reset leftClicks to 0.
      clearTimeout(tOut);
      tOut = setTimeout(noDoubles, 100);
    };

    leftClicks++;
    if (leftClicks === 2) {
      //2 fast clicks
    }

  } else if (evt.button === 2) {
    //right click
  } else {
    //mouse wheel
  }

};

 

Link to comment
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...
 Share

  • Recently Browsing   0 members

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