Skip to content

Commit 42a7034

Browse files
author
Elliot
committed
Fix CCScrollView horizontal scrolling from being backwards. Make numHorizontal/Vertical pages calculations more accurate.
1 parent 7d485e5 commit 42a7034

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

cocos2d-ui/CCScrollView.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,15 +330,15 @@ - (int) numHorizontalPages
330330
if (!_pagingEnabled) return 0;
331331
if (!self.contentSizeInPoints.width || !_contentNode.contentSizeInPoints.width) return 0;
332332

333-
return _contentNode.contentSizeInPoints.width / self.contentSizeInPoints.width;
333+
return roundf(_contentNode.contentSizeInPoints.width / self.contentSizeInPoints.width);
334334
}
335335

336336
- (int) numVerticalPages
337337
{
338338
if (!_pagingEnabled) return 0;
339339
if (!self.contentSizeInPoints.height || !_contentNode.contentSizeInPoints.height) return 0;
340340

341-
return _contentNode.contentSizeInPoints.height / self.contentSizeInPoints.height;
341+
return roundf(_contentNode.contentSizeInPoints.height / self.contentSizeInPoints.height);
342342
}
343343

344344
#pragma mark Panning and setting position
@@ -413,7 +413,7 @@ - (void) setScrollPosition:(CGPoint)newPos animated:(BOOL)animated
413413
- (void)updateAndroidScrollTranslation:(CGPoint)worldPosition
414414
{
415415
#if __CC_PLATFORM_ANDROID
416-
_rawScrollTranslation = [self convertToWindowSpace:worldPosition];
416+
_rawScrollTranslation = [self convertToWindowSpace:CGPointMake(-worldPosition.x, worldPosition.y)];
417417
#endif
418418
}
419419

@@ -501,7 +501,7 @@ - (void) update:(CCTime)df
501501

502502
_contentNode.position = ccpAdd(_contentNode.position, delta);
503503

504-
[self updateAndroidScrollTranslation:CGPointMake(_contentNode.position.x, _contentNode.position.y * -1)];
504+
[self updateAndroidScrollTranslation:CGPointMake(_contentNode.position.x * -1, _contentNode.position.y * -1)];
505505

506506
// Deaccelerate layer
507507
float deaccelerationX = kCCScrollViewDeacceleration;
@@ -863,7 +863,7 @@ - (BOOL)onScroll:(AndroidMotionEvent *)start end:(AndroidMotionEvent *)end dista
863863
dx /= scaleFactor;
864864
dy /= scaleFactor;
865865

866-
_rawScrollTranslation.x += dx;
866+
_rawScrollTranslation.x -= dx;
867867
_rawScrollTranslation.y -= dy;
868868

869869
CCDirector* dir = [CCDirector sharedDirector];

0 commit comments

Comments
 (0)