void CCSwipeGestureRecognizer::ccTouchEnded(CCTouch * pTouch, CCEvent * pEvent)
{
    CCPoint finalPosition = pTouch->getLocation();
    if (!isPositionBetweenBounds(finalPosition)) {
        isRecognizing = false;
        return;
    }
    
    //distance between initial and final point of touch
    float distance = distanceBetweenPoints(initialPosition, finalPosition);
    
    struct cc_timeval currentTime;
    CCTime::gettimeofdayCocos2d(&currentTime, NULL);
    
    double duration = CCTime::timersubCocos2d(&startTime, &currentTime); //duration in milliseconds
    
    //check that minimum distance has been reached
    //check that maximum duration hasn't been reached
    //check if the direction of the swipe is correct
    int dir = 0;
    if (distance>=kSwipeMinDistance && duration<=kSwipeMaxDuration && checkSwipeDirection(initialPosition,finalPosition,dir)) {
        CCSwipe * swipe = CCSwipe::create();
        swipe->direction = (CCSwipeGestureRecognizerDirection)dir;
        swipe->location = initialPosition;
        
        gestureRecognized(swipe);
        if (cancelsTouchesInView) stopTouchesPropagation(createSetWithTouch(pTouch), pEvent); //cancel touch over other views
    }
    
    isRecognizing = false;
}
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 CCPanGestureRecognizer::ccTouchEnded(CCTouch * pTouch, CCEvent * pEvent)
{
    isRecognizing = false;
    
    //cancel touch over other views if necessary
    if (cancelsTouchesInView) {
        stopTouchesPropagation(createSetWithTouch(pTouch), pEvent);
    }
}
void CCPinchGestureRecognizer::ccTouchEnded(CCTouch * pTouch, CCEvent * pEvent)
{
    isRecognizing = false;
    lastDistance = 0;
    touchNumber--;
    touches->removeObject(pTouch);
    
    //cancel touch over other views if necessary
    if (cancelsTouchesInView) {
        stopTouchesPropagation(createSetWithTouch(pTouch), pEvent);
    }
}
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();
}