Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
souleaterjh opened this issue Aug 4, 2014 · 1 comment

Comments

@souleaterjh
Copy link

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 added a commit to souleaterjh/cocos2d-iphone that referenced this issue Aug 4, 2014
…t the end of a scroll instead of once every update loop.
@andykorth
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants