void CCTapGestureRecognizer::ccTouchEnded(CCTouch * pTouch, CCEvent * pEvent)
{
    //calculate duration
    CCTime::gettimeofdayCocos2d(&endTime, NULL);
    double duration = CCTime::timersubCocos2d(&startTime, &endTime); //duration of tap in milliseconds
    
    //calculate distance
    finalPosition = pTouch->getLocation();
    float distance = distanceBetweenPoints(initialPosition, finalPosition);
    
    //tap was successful
    if (duration<=kTapMaxDuration && distance<=kTapMaxDistance) {
        taps++;
        if (taps==(int)numberOfTapsRequired) {
            CCTap * tap = CCTap::create();
            tap->location = initialPosition;
            
            gestureRecognized(tap);
            if (cancelsTouchesInView) stopTouchesPropagation(createSetWithTouch(pTouch), pEvent); //cancel touch over other views
            stopGestureRecognition();
        }
    }
    else {
        stopGestureRecognition();
    }
}
void CCLongPressGestureRecognizer::timerDidEnd(float dt)
{
    CCLongPress * longPress = CCLongPress::create();
    longPress->location = currLocation;

    gestureRecognized(longPress);
    CCTime::gettimeofdayCocos2d(&startTime, NULL);

    isMoving = true;

    if (cancelsTouchesInView) stopTouchesPropagation(createSetWithTouch(currTouch), currEvent); //cancel touch over other views

    stopGestureRecognition();
}
bool CCTapGestureRecognizer::ccTouchBegan(CCTouch * pTouch, CCEvent * pEvent)
{
    if (isRecognizing && taps==0) {
        stopGestureRecognition();
        return false;
    }
    
    initialPosition = pTouch->getLocation();
    
    if (!isPositionBetweenBounds(initialPosition)) return false;
    
    CCTime::gettimeofdayCocos2d(&startTime, NULL);
    
    if (taps>0 && taps<(int)numberOfTapsRequired) {
        float distance = distanceBetweenPoints(finalPosition, initialPosition); //distance between taps
        double duration = CCTime::timersubCocos2d(&endTime, &startTime); //duration between taps
        if (duration>kTapMaxDurationBetweenTaps || distance>kTapMaxDistanceBetweenTaps) {
            stopGestureRecognition();
        }
    }
    
    isRecognizing = true;
    return true;
}
bool CCLongPressGestureRecognizer::ccTouchBegan(CCTouch * pTouch, CCEvent * pEvent)
{
    if (isRecognizing) {
        stopGestureRecognition();
        return false;
    }

    isMoving = false;

    currLocation = pTouch->getLocation();
    if (!isPositionBetweenBounds(currLocation)) return false;

    currEvent = pEvent;
    currTouch = pTouch;

    schedule(schedule_selector(CCLongPressGestureRecognizer::timerDidEnd), minimumPressDuration);

    isRecognizing = true;
    return true;
}
void CCLongPressGestureRecognizer::ccTouchEnded(CCTouch * pTouch, CCEvent * pEvent)
{
    stopGestureRecognition();
    isMoving = false;
}