cocos2d-x のCCScrollViewが怪しい(2)

2014年3月3日

前回、この記事で話した、CCScrollViewが怪しい件の続きです。
どうも、この関数の動きが怪しい。

void CCScrollView::deaccelerateScrolling(float dt)
{
    if (m_bDragging)
    {
        this->unschedule(schedule_selector(CCScrollView::deaccelerateScrolling));
        return;
    }
    float newX, newY;
    CCPoint maxInset, minInset;
    m_pContainer->setPosition(ccpAdd(m_pContainer->getPosition(), m_tScrollDistance));
    if (m_bBounceable)
    {
        maxInset = m_fMaxInset;
        minInset = m_fMinInset;
    }
    else
    {
        maxInset = this->maxContainerOffset();
        minInset = this->minContainerOffset();
    }
    //check to see if offset lies within the inset bounds
    newX     = MIN(m_pContainer->getPosition().x, maxInset.x);
    newX     = MAX(newX, minInset.x);
    newY     = MIN(m_pContainer->getPosition().y, maxInset.y);
    newY     = MAX(newY, minInset.y);
    newX = m_pContainer->getPosition().x;
    newY = m_pContainer->getPosition().y;
    m_tScrollDistance     = ccpSub(m_tScrollDistance, ccp(newX - m_pContainer->getPosition().x, newY - m_pContainer->getPosition().y));
    m_tScrollDistance     = ccpMult(m_tScrollDistance, SCROLL_DEACCEL_RATE);
    this->setContentOffset(ccp(newX,newY));
    if ((fabsf(m_tScrollDistance.x) <= SCROLL_DEACCEL_DIST &&
    fabsf(m_tScrollDistance.y) <= SCROLL_DEACCEL_DIST) ||
    newY > maxInset.y || newY < minInset.y ||
    newX > maxInset.x || newX < minInset.x ||
    newX == maxInset.x || newX == minInset.x ||
    newY == maxInset.y || newY == minInset.y)
    {
      this->unschedule(schedule_selector(CCScrollView::deaccelerateScrolling));
      this->relocateContainer(true);
    }
}

まず、
//check to see if offset lies within the inset bounds
から下のnewX, newYの代入が怪しすぎる。
なんで、最後の式で置き換えているから、MIN, MAXしているところ意味ないんじゃない?
それにデバックしてみるとなんか頻繁に、最後のif文に入っている気がする。
これたぶん、スクロールの慣性が終わるときに通るルートだから頻繁じゃだめだよね?
maxContainerOffsetが鍵になりそうなきがする。

cocos2d-x

Posted by koheizi