Exemplo n.º 1
0
void ScrollViewClass::ccTouchEnded(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent)
{
    CCPoint curPos = CCDirector::sharedDirector()->convertToGL(pTouch->getLocationInView());
    CCPoint prePos = startDownPos;
    
    CCPoint diffPos = ccpSub(curPos, prePos);
    if (ccpLength(ccp(diffPos.x, 0)) > DELTA_SCROLL) {//means scroll
        int count = childLayerArray->count();
        int index = curPageNum;
        if (diffPos.x < 0) {
            if ((index + 1) >= count) {
                this->gotoPage(curPageNum);
            }
            else
            {
                this->gotoPage(++curPageNum);
            }
        }
        else
        {
            if ((index - 1) <= 0) {
                curPageNum = 0;
                this->gotoPage(curPageNum);
            }
            else
            {
                this->gotoPage(--curPageNum);
            }
        }
    }
    else
    {
        if (isTouchSel) {
            CCLayer* curLayer = (CCLayer*)childLayerArray->objectAtIndex(curPageNum);
            curLayer->ccTouchEnded(pTouch, pEvent);
        }
    }
}