61
61
#pragma mark -
62
62
#pragma mark Helper classes
63
63
64
-
65
64
#if __CC_PLATFORM_IOS
66
65
@interface CCTapDownGestureRecognizer : UIGestureRecognizer
67
66
@end
@@ -172,6 +171,7 @@ @implementation CCScrollView {
172
171
#elif __CC_PLATFORM_ANDROID
173
172
CCGestureListener *_listener;
174
173
AndroidGestureDetector *_detector;
174
+ CGPoint _rawScrollTranslation;
175
175
#endif
176
176
}
177
177
@@ -355,6 +355,8 @@ - (void) setScrollPosition:(CGPoint)newPos animated:(BOOL)animated
355
355
newPos.x = MAX (MIN (newPos.x , self.maxScrollX ), self.minScrollX );
356
356
newPos.y = MAX (MIN (newPos.y , self.maxScrollY ), self.minScrollY );
357
357
358
+ [self updateAndroidScrollTranslation: newPos];
359
+
358
360
BOOL xMoved = (newPos.x != self.scrollPosition .x );
359
361
BOOL yMoved = (newPos.y != self.scrollPosition .y );
360
362
@@ -409,6 +411,14 @@ - (void) setScrollPosition:(CGPoint)newPos animated:(BOOL)animated
409
411
}
410
412
}
411
413
414
+ - (void )updateAndroidScrollTranslation : (CGPoint)worldPosition
415
+ {
416
+ #if __CC_PLATFORM_ANDROID
417
+ _rawScrollTranslation = [self convertToWindowSpace: worldPosition];
418
+ #endif
419
+ }
420
+
421
+
412
422
- (void ) xAnimationDone
413
423
{
414
424
_animatingX = NO ;
@@ -492,6 +502,8 @@ - (void) update:(CCTime)df
492
502
493
503
_contentNode.position = ccpAdd (_contentNode.position , delta);
494
504
505
+ [self updateAndroidScrollTranslation: CGPointMake (_contentNode.position.x, _contentNode.position.y * -1 )];
506
+
495
507
// Deaccelerate layer
496
508
float deaccelerationX = kCCScrollViewDeacceleration ;
497
509
float deaccelerationY = kCCScrollViewDeacceleration ;
@@ -820,24 +832,23 @@ - (BOOL)onScroll:(AndroidMotionEvent *)start end:(AndroidMotionEvent *)end dista
820
832
_velocity = CGPointZero;
821
833
822
834
// Note about start and end events: We will get a CCTouchPhaseBegan for the start event, followed by CCTouchPhaseMoved in the end event
823
- static CGPoint rawTranslation;
824
835
CCTouchPhase phase = [self handleGestureEvent: start end: end];
825
836
826
837
if (phase == CCTouchPhaseCancelled || phase == CCTouchPhaseEnded)
827
- rawTranslation = CGPointMake (0 .0f , 0 .0f );
838
+ _rawScrollTranslation = CGPointMake (0 .0f , 0 .0f );
828
839
829
840
float scaleFactor = [[CCDirector sharedDirector ] view ].contentScaleFactor ;
830
841
831
842
dx /= scaleFactor;
832
843
dy /= scaleFactor;
833
844
834
- rawTranslation .x += dx;
835
- rawTranslation .y -= dy;
845
+ _rawScrollTranslation .x += dx;
846
+ _rawScrollTranslation .y -= dy;
836
847
837
848
CCDirector* dir = [CCDirector sharedDirector ];
838
849
[[CCActivity currentActivity ] runOnGameThread: ^{
839
850
840
- CGPoint translation = [dir convertToGL: rawTranslation ];
851
+ CGPoint translation = [dir convertToGL: _rawScrollTranslation ];
841
852
translation = [self convertToNodeSpace: translation];
842
853
843
854
if (phase == CCTouchPhaseBegan)
@@ -868,6 +879,7 @@ - (BOOL)onScroll:(AndroidMotionEvent *)start end:(AndroidMotionEvent *)end dista
868
879
869
880
// Update position
870
881
[self panLayerToTarget: newPos];
882
+
871
883
}
872
884
else if (phase == CCTouchPhaseEnded)
873
885
{
@@ -891,7 +903,7 @@ - (BOOL)onFling:(AndroidMotionEvent *)start end:(AndroidMotionEvent *)end veloci
891
903
static CGPoint rawTranslationFling;
892
904
893
905
CCTouchPhase phase = [self handleGestureEvent: start end: end];
894
-
906
+
895
907
if (phase == CCTouchPhaseCancelled || phase == CCTouchPhaseEnded)
896
908
rawTranslationFling = CGPointMake (0 .0f , 0 .0f );
897
909
0 commit comments