CCScrollView scrollViewDidScroll: fires every update loop instead of once at the end
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.
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.