Search code examples
cocos2d-xdouble-clickmultiplatform

How to detect double click with cocos2d-x


How do I port this cocos2d-iphone code to cocos2d-x?

(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event  {
 NSSet *allTouches = [event allTouches]; 
switch ([allTouches count])    {
case 1:  
    {
        UITouch *touch = [[allTouches allObjects] objectAtIndex:0];
        switch([touch tapCount]) 
        { 
             case 1:
                  // 单击!
                 break;
             case 2:
                //Double tap.
               // 双击! 
                break;
        } 
   break;    
   } 
}

Solution

  • There is no function to implement this,we can implement this by test the tick between two clicks.In general,the time interval of double click is between 250ms~300ms.Use this to get the system's current number of milliseconds

    long millisecondNow()
    {
        struct cc_timeval now;
        CCTime::gettimeofdayCocos2d(&now, NULL);
        return (now.tv_sec * 1000 + now.tv_sec / 1000);
    }