cocos2d-objc icon indicating copy to clipboard operation
cocos2d-objc copied to clipboard

CCScrollView scrollViewDidScroll: fires every update loop instead of once at the end

Open souleaterjh opened this issue 11 years ago • 1 comments

The issue is inside the CCMoveToY and CCMoveToX that CCScrollView uses.

Here is what the update: function looks like:

CCMoveToY

-(void) update: (CCTime) t
{
    CCNode *node = (CCNode*)_target;

    float positionDelta = _endPosition - _startPos;
    float y = _startPos + positionDelta * t;
    float x = node.position.x;

    node.position = ccp(x,y);
    block();
}

It should look like this:

-(void) update: (CCTime) t
{
    CCNode *node = (CCNode*)_target;

    float positionDelta = _endPosition - _startPos;
    float y = _startPos + positionDelta * t;
    float x = node.position.x;

    node.position = ccp(x,y);
    if (node.position.y == _endPosition) {
        block();
    }
}

CCMoveToX

-(void) update: (CCTime) t
{
    CCNode *node = (CCNode*)_target;

    float positionDelta = _endPosition - _startPos;
    float x = _startPos + positionDelta * t;
    float y = node.position.y;

    node.position = ccp(x,y);
    block();
}

What this should look like:

-(void) update: (CCTime) t
{
    CCNode *node = (CCNode*)_target;

    float positionDelta = _endPosition - _startPos;
    float x = _startPos + positionDelta * t;
    float y = node.position.y;

    node.position = ccp(x,y);
    if (node.position.x == _endPosition) {
        block();
    }
}

I've made the change in my version, should I submit a pull request or you guys can fix this yourself? This should be quite quick.

If you guys wanted a callback to fire every update loop, you might want to name it something along the lines of scrollViewScrolling: or something. I'm using this to get an idea of when the scroll has finished, I hope I'm not wrong here.

souleaterjh avatar Aug 04 '14 11:08 souleaterjh

Calling each frame is intentional. It's designed to mirror Apple's UIScrollViewDelegate: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIScrollViewDelegate_Protocol/index.html#//apple_ref/occ/intfm/UIScrollViewDelegate/scrollViewDidScroll:

For UIScrollViews, scrollViewWillBeginDragging and scrollViewDidEndDragging/scrollViewWillEndDragging are called once each at the beginning and end. I think that's what you're looking for. Equivalent delegates do exist in CCScrollViewDelegate.

andykorth avatar Jan 28 '15 22:01 andykorth