Cocoa touch cocos2d中的双击

Cocoa touch cocos2d中的双击,cocoa-touch,cocos2d-iphone,Cocoa Touch,Cocos2d Iphone,我正在尝试用cocos2d开发一个游戏。我现在卡住了。我不知道如何检测双击事件,就像在windows中双击一样。我试着使用 NSArray * allTouches = [touches allObjects]; int count = [allTouches count]; 在cctouchesend中 但当双重接触同时发生时,这似乎起作用。我想知道Windows中的情况 谁能给我一些建议吗? 提前感谢。如果您使用targetedTouchDelegate,您可以执行以下操作: - (voi

我正在尝试用cocos2d开发一个游戏。我现在卡住了。我不知道如何检测双击事件,就像在windows中双击一样。我试着使用

NSArray * allTouches = [touches allObjects];
int count = [allTouches count];
cctouchesend中

但当双重接触同时发生时,这似乎起作用。我想知道Windows中的情况

谁能给我一些建议吗?
提前感谢。

如果您使用targetedTouchDelegate,您可以执行以下操作:

- (void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event {
    if(touch.tapCount==1) MPLOG(@"ONE TAP");
    if(touch.tapCount==2) MPLOG(@"TWO TAPS");
    return;
}

当双击发生时,您将得到两次触碰(当有双击时,这将记录“一次触碰”和“两次触碰”)。由您自己决定您的状态并完成您的任务。

您在谈论mac和windows中的多点触摸、双指点击或双击

如果它是像在mac和windows中那样双击,那么这里有一个解决方案

你可以用两种方法来做

  • 在本文中使用LearnCos2D建议的UITapGestureRecognitor(设置为检测双击)

  • 使用时差手动双击跟踪

  • //在接口文件中对此进行标记

     NSTimeInterval      mLastTapTime;
    
    在实现文件中:

    -(id)init
    {
        if(self = [super init])
        {
             mLastTapTime = [NSDate timeIntervalSinceReferenceDate];
        }
        return self;
    }
    
    //接触法

    NSTimeInterval currentTime = [NSDate timeIntervalSinceReferenceDate];
    NSTimeInterval diff = currentTime - mLastTapTime;
    
    if(diff < 0.5 ) //0.5 or less
    {
         //double tap
    }
    
    mLastTapTime = [NSDate timeIntervalSinceReferenceDate];
    
    NSTimeInterval currentTime=[NSDate timeintervalnceReferenceDate];
    NSTimeInterval diff=当前时间-mLastTapTime;
    如果(差值<0.5)//0.5或更小
    {
    //双击
    }
    mLastTapTime=[NSDate timeIntervalSinceReferenceDate];
    
    UITapGestureRecognitizer可以设置为测试双击,请参见:您是一个图例。多好的解决方案啊。非常感谢。