Skip to content

Commit 227cb11

Browse files
committed
Merge branch 'headless-develop' of github.com:spritebuilder/cocos2d-swift into headless-develop
2 parents 0e8e6fb + ec8dd3d commit 227cb11

File tree

13 files changed

+201
-31
lines changed

13 files changed

+201
-31
lines changed

.gitmodules

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11
[submodule "external/Chipmunk"]
22
path = external/Chipmunk
33
url=https://github.com/slembcke/Chipmunk2D.git
4+
[submodule "external/ogg"]
5+
path = external/ogg
6+
url = [email protected]:apportable/ogg.git
7+
branch = apportable
8+
[submodule "external/tremor"]
9+
path = external/tremor
10+
url = [email protected]:apportable/tremor.git
11+
branch = apportable

cocos2d-ios.xcodeproj/project.pbxproj

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,7 @@
673673
E0F924711224140400EF2362 /* CCTexturePVR.h in Headers */ = {isa = PBXBuildFile; fileRef = E0F9246F1224140400EF2362 /* CCTexturePVR.h */; };
674674
E0F924721224140400EF2362 /* CCTexturePVR.m in Sources */ = {isa = PBXBuildFile; fileRef = E0F924701224140400EF2362 /* CCTexturePVR.m */; };
675675
E0F92AC41224559800EF2362 /* CCNS.h in Headers */ = {isa = PBXBuildFile; fileRef = E0F92AC31224559800EF2362 /* CCNS.h */; };
676+
FC55599E1991A26000E29CCE /* libtremor.a in Frameworks */ = {isa = PBXBuildFile; fileRef = FC55599B1991A25000E29CCE /* libtremor.a */; };
676677
/* End PBXBuildFile section */
677678

678679
/* Begin PBXContainerItemProxy section */
@@ -697,6 +698,20 @@
697698
remoteGlobalIDString = D309B21217EFE2EF00AA52C8;
698699
remoteInfo = "ObjectiveChipmunk-iPhone";
699700
};
701+
FC55599A1991A25000E29CCE /* PBXContainerItemProxy */ = {
702+
isa = PBXContainerItemProxy;
703+
containerPortal = FC5559951991A25000E29CCE /* tremor.xcodeproj */;
704+
proxyType = 2;
705+
remoteGlobalIDString = FC76226219919ECD0001BCF4;
706+
remoteInfo = tremor;
707+
};
708+
FC55599C1991A25A00E29CCE /* PBXContainerItemProxy */ = {
709+
isa = PBXContainerItemProxy;
710+
containerPortal = FC5559951991A25000E29CCE /* tremor.xcodeproj */;
711+
proxyType = 1;
712+
remoteGlobalIDString = FC76226119919ECD0001BCF4;
713+
remoteInfo = tremor;
714+
};
700715
/* End PBXContainerItemProxy section */
701716

702717
/* Begin PBXCopyFilesBuildPhase section */
@@ -1089,6 +1104,8 @@
10891104
E0F9246F1224140400EF2362 /* CCTexturePVR.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCTexturePVR.h; sourceTree = "<group>"; };
10901105
E0F924701224140400EF2362 /* CCTexturePVR.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCTexturePVR.m; sourceTree = "<group>"; };
10911106
E0F92AC31224559800EF2362 /* CCNS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCNS.h; sourceTree = "<group>"; };
1107+
FC5559951991A25000E29CCE /* tremor.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = tremor.xcodeproj; path = external/tremor/android/tremor/tremor.xcodeproj; sourceTree = "<group>"; };
1108+
FC55599F1991A26300E29CCE /* libogg.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libogg.a; path = "external/ogg/android/ogg/build/Debug-android/libogg.a"; sourceTree = "<group>"; };
10921109
/* End PBXFileReference section */
10931110

10941111
/* Begin PBXFrameworksBuildPhase section */
@@ -1122,6 +1139,7 @@
11221139
isa = PBXFrameworksBuildPhase;
11231140
buildActionMask = 2147483647;
11241141
files = (
1142+
FC55599E1991A26000E29CCE /* libtremor.a in Frameworks */,
11251143
D291DCC2195B2FA100278EC0 /* libObjectiveChipmunk-iPhone.a in Frameworks */,
11261144
D2FEB745194F6C9E00FC0574 /* CoreText.framework in Frameworks */,
11271145
D2FEB747194F6C9E00FC0574 /* Foundation.framework in Frameworks */,
@@ -1167,6 +1185,7 @@
11671185
29B97323FDCFA39411CA2CEA /* Frameworks */ = {
11681186
isa = PBXGroup;
11691187
children = (
1188+
FC55599F1991A26300E29CCE /* libogg.a */,
11701189
D24FAEEB198014B90043E27D /* GLKit.framework */,
11711190
D289C1C1197440BC00B68E3D /* BridgeKitV3.framework */,
11721191
D28A2E201954F85700ADC03D /* AVFoundation.framework */,
@@ -1187,6 +1206,7 @@
11871206
501756090F335CE900624901 /* external */ = {
11881207
isa = PBXGroup;
11891208
children = (
1209+
FC5559951991A25000E29CCE /* tremor.xcodeproj */,
11901210
B759E5281880C66900E8166C /* Chipmunk7-ios.xcodeproj */,
11911211
B7705F8A1831A07B0043CC67 /* ObjectAL */,
11921212
);
@@ -1879,6 +1899,14 @@
18791899
path = iOS;
18801900
sourceTree = "<group>";
18811901
};
1902+
FC5559961991A25000E29CCE /* Products */ = {
1903+
isa = PBXGroup;
1904+
children = (
1905+
FC55599B1991A25000E29CCE /* libtremor.a */,
1906+
);
1907+
name = Products;
1908+
sourceTree = "<group>";
1909+
};
18821910
/* End PBXGroup section */
18831911

18841912
/* Begin PBXHeadersBuildPhase section */
@@ -2297,6 +2325,7 @@
22972325
buildRules = (
22982326
);
22992327
dependencies = (
2328+
FC55599D1991A25A00E29CCE /* PBXTargetDependency */,
23002329
D2FEB60E194F6C9E00FC0574 /* PBXTargetDependency */,
23012330
);
23022331
name = cocos2dAndroid;
@@ -2330,6 +2359,10 @@
23302359
ProductGroup = B759E5291880C66900E8166C /* Products */;
23312360
ProjectRef = B759E5281880C66900E8166C /* Chipmunk7-ios.xcodeproj */;
23322361
},
2362+
{
2363+
ProductGroup = FC5559961991A25000E29CCE /* Products */;
2364+
ProjectRef = FC5559951991A25000E29CCE /* tremor.xcodeproj */;
2365+
},
23332366
);
23342367
projectRoot = "";
23352368
targets = (
@@ -2349,6 +2382,13 @@
23492382
remoteRef = B759E52C1880C66900E8166C /* PBXContainerItemProxy */;
23502383
sourceTree = BUILT_PRODUCTS_DIR;
23512384
};
2385+
FC55599B1991A25000E29CCE /* libtremor.a */ = {
2386+
isa = PBXReferenceProxy;
2387+
fileType = archive.ar;
2388+
path = libtremor.a;
2389+
remoteRef = FC55599A1991A25000E29CCE /* PBXContainerItemProxy */;
2390+
sourceTree = BUILT_PRODUCTS_DIR;
2391+
};
23522392
/* End PBXReferenceProxy section */
23532393

23542394
/* Begin PBXResourcesBuildPhase section */
@@ -2698,6 +2738,11 @@
26982738
name = "ObjectiveChipmunk-iPhone";
26992739
targetProxy = D2FEB60F194F6C9E00FC0574 /* PBXContainerItemProxy */;
27002740
};
2741+
FC55599D1991A25A00E29CCE /* PBXTargetDependency */ = {
2742+
isa = PBXTargetDependency;
2743+
name = tremor;
2744+
targetProxy = FC55599C1991A25A00E29CCE /* PBXContainerItemProxy */;
2745+
};
27012746
/* End PBXTargetDependency section */
27022747

27032748
/* Begin XCBuildConfiguration section */
@@ -2799,7 +2844,7 @@
27992844
MACOSX_DEPLOYMENT_TARGET = "$(inherited)";
28002845
OTHER_LDFLAGS = "";
28012846
PRODUCT_NAME = "$(TARGET_NAME)";
2802-
SDKROOT = apportablesdk1.0;
2847+
SDKROOT = sbpbeta;
28032848
};
28042849
name = Debug;
28052850
};
@@ -2823,7 +2868,7 @@
28232868
MACOSX_DEPLOYMENT_TARGET = "$(inherited)";
28242869
OTHER_LDFLAGS = "";
28252870
PRODUCT_NAME = "$(TARGET_NAME)";
2826-
SDKROOT = apportablesdk1.0;
2871+
SDKROOT = sbpbeta;
28272872
};
28282873
name = Release;
28292874
};
@@ -2985,11 +3030,12 @@
29853030
"$(SDKROOT)/usr/lib/armeabi",
29863031
"$(SDKROOT)/usr/lib/armv7a",
29873032
"$(SDKROOT)/usr/lib/x86",
3033+
"$(PROJECT_DIR)/external/ogg/android/ogg/build/Debug-android",
29883034
);
29893035
ONLY_ACTIVE_ARCH = YES;
29903036
OTHER_LDFLAGS = "";
29913037
PRODUCT_NAME = cocos2dAndroid;
2992-
SDKROOT = apportablesdk1.0;
3038+
SDKROOT = sbpbeta;
29933039
SKIP_INSTALL = YES;
29943040
};
29953041
name = Debug;
@@ -3029,10 +3075,11 @@
30293075
"$(SDKROOT)/usr/lib/armeabi",
30303076
"$(SDKROOT)/usr/lib/armv7a",
30313077
"$(SDKROOT)/usr/lib/x86",
3078+
"$(PROJECT_DIR)/external/ogg/android/ogg/build/Debug-android",
30323079
);
30333080
OTHER_LDFLAGS = "";
30343081
PRODUCT_NAME = cocos2dAndroid;
3035-
SDKROOT = apportablesdk1.0;
3082+
SDKROOT = sbpbeta;
30363083
SKIP_INSTALL = YES;
30373084
ZERO_LINK = NO;
30383085
};

cocos2d-ui/CCScrollView.m

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
#pragma mark -
6262
#pragma mark Helper classes
6363

64-
6564
#if __CC_PLATFORM_IOS
6665
@interface CCTapDownGestureRecognizer : UIGestureRecognizer
6766
@end
@@ -172,6 +171,7 @@ @implementation CCScrollView {
172171
#elif __CC_PLATFORM_ANDROID
173172
CCGestureListener *_listener;
174173
AndroidGestureDetector *_detector;
174+
CGPoint _rawScrollTranslation;
175175
#endif
176176
}
177177

@@ -214,7 +214,6 @@ - (id) initWithContentNode:(CCNode*)contentNode
214214
_listener = [[CCGestureListener alloc] init];
215215
_listener.delegate = (id<CCGestureListenerDelegate>)self;
216216
_detector = [[AndroidGestureDetector alloc] initWithContext:[CCActivity currentActivity] listener:_listener];
217-
[[[CCDirector sharedDirector] view] addGestureDetector:_detector];
218217
});
219218
#elif __CC_PLATFORM_MAC
220219

@@ -355,6 +354,8 @@ - (void) setScrollPosition:(CGPoint)newPos animated:(BOOL)animated
355354
newPos.x = MAX(MIN(newPos.x, self.maxScrollX), self.minScrollX);
356355
newPos.y = MAX(MIN(newPos.y, self.maxScrollY), self.minScrollY);
357356

357+
[self updateAndroidScrollTranslation:newPos];
358+
358359
BOOL xMoved = (newPos.x != self.scrollPosition.x);
359360
BOOL yMoved = (newPos.y != self.scrollPosition.y);
360361

@@ -409,6 +410,14 @@ - (void) setScrollPosition:(CGPoint)newPos animated:(BOOL)animated
409410
}
410411
}
411412

413+
- (void)updateAndroidScrollTranslation:(CGPoint)worldPosition
414+
{
415+
#if __CC_PLATFORM_ANDROID
416+
_rawScrollTranslation = [self convertToWindowSpace:worldPosition];
417+
#endif
418+
}
419+
420+
412421
- (void) xAnimationDone
413422
{
414423
_animatingX = NO;
@@ -492,6 +501,8 @@ - (void) update:(CCTime)df
492501

493502
_contentNode.position = ccpAdd(_contentNode.position, delta);
494503

504+
[self updateAndroidScrollTranslation:CGPointMake(_contentNode.position.x, _contentNode.position.y * -1)];
505+
495506
// Deaccelerate layer
496507
float deaccelerationX = kCCScrollViewDeacceleration;
497508
float deaccelerationY = kCCScrollViewDeacceleration;
@@ -740,8 +751,11 @@ - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecogni
740751
return (otherGestureRecognizer == _panRecognizer || otherGestureRecognizer == _tapRecognizer);
741752
}
742753

754+
#elif __CC_PLATFORM_ANDROID
755+
743756
- (void) onEnterTransitionDidFinish
744757
{
758+
#if __CC_PLATFORM_IOS
745759
// Add recognizers to view
746760
UIView* view = [CCDirector sharedDirector].view;
747761

@@ -751,12 +765,22 @@ - (void) onEnterTransitionDidFinish
751765
[recognizers insertObject:_tapRecognizer atIndex:0];
752766

753767
view.gestureRecognizers = recognizers;
754-
768+
#elif __CC_PLATFORM_ANDROID
769+
dispatch_async(dispatch_get_main_queue(), ^{
770+
if(_detector)
771+
{
772+
[[[CCDirector sharedDirector] view] addGestureDetector:_detector];
773+
}
774+
});
775+
#endif
755776
[super onEnterTransitionDidFinish];
756777
}
757778

779+
780+
758781
- (void) onExitTransitionDidStart
759782
{
783+
#if __CC_PLATFORM_IOS
760784
// Remove recognizers from view
761785
UIView* view = [CCDirector sharedDirector].view;
762786

@@ -765,11 +789,19 @@ - (void) onExitTransitionDidStart
765789
[recognizers removeObject:_tapRecognizer];
766790

767791
view.gestureRecognizers = recognizers;
792+
#elif __CC_PLATFORM_ANDROID
793+
dispatch_async(dispatch_get_main_queue(), ^{
794+
if(_detector)
795+
{
796+
[[[CCDirector sharedDirector] view] removeGestureDetector:_detector];
797+
}
798+
});
799+
#endif
768800

769801
[super onExitTransitionDidStart];
770802
}
771803

772-
#elif __CC_PLATFORM_ANDROID
804+
773805

774806
- (CCTouchPhase)handleGestureEvent:(AndroidMotionEvent *)start end:(AndroidMotionEvent *)end
775807
{
@@ -820,24 +852,23 @@ - (BOOL)onScroll:(AndroidMotionEvent *)start end:(AndroidMotionEvent *)end dista
820852
_velocity = CGPointZero;
821853

822854
// 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;
824855
CCTouchPhase phase = [self handleGestureEvent:start end:end];
825856

826857
if(phase == CCTouchPhaseCancelled || phase == CCTouchPhaseEnded)
827-
rawTranslation = CGPointMake(0.0f, 0.0f);
858+
_rawScrollTranslation = CGPointMake(0.0f, 0.0f);
828859

829860
float scaleFactor = [[CCDirector sharedDirector] view].contentScaleFactor;
830861

831862
dx /= scaleFactor;
832863
dy /= scaleFactor;
833864

834-
rawTranslation.x += dx;
835-
rawTranslation.y -= dy;
865+
_rawScrollTranslation.x += dx;
866+
_rawScrollTranslation.y -= dy;
836867

837868
CCDirector* dir = [CCDirector sharedDirector];
838869
[[CCActivity currentActivity] runOnGameThread:^{
839870

840-
CGPoint translation = [dir convertToGL:rawTranslation];
871+
CGPoint translation = [dir convertToGL:_rawScrollTranslation];
841872
translation = [self convertToNodeSpace:translation];
842873

843874
if (phase == CCTouchPhaseBegan)
@@ -868,6 +899,7 @@ - (BOOL)onScroll:(AndroidMotionEvent *)start end:(AndroidMotionEvent *)end dista
868899

869900
// Update position
870901
[self panLayerToTarget:newPos];
902+
871903
}
872904
else if (phase == CCTouchPhaseEnded)
873905
{
@@ -891,7 +923,7 @@ - (BOOL)onFling:(AndroidMotionEvent *)start end:(AndroidMotionEvent *)end veloci
891923
static CGPoint rawTranslationFling;
892924

893925
CCTouchPhase phase = [self handleGestureEvent:start end:end];
894-
926+
895927
if(phase == CCTouchPhaseCancelled || phase == CCTouchPhaseEnded)
896928
rawTranslationFling = CGPointMake(0.0f, 0.0f);
897929

@@ -918,9 +950,6 @@ - (BOOL)onFling:(AndroidMotionEvent *)start end:(AndroidMotionEvent *)end veloci
918950
CCDirector* dir = [CCDirector sharedDirector];
919951
[[CCActivity currentActivity] runOnGameThread:^{
920952

921-
CCResponderManager *mgr = [[CCDirector sharedDirector] responderManager];
922-
[mgr removeAllResponders];
923-
924953
CGPoint translation = [dir convertToGL:rawTranslationFling];
925954
translation = [self convertToNodeSpace:translation];
926955

cocos2d-ui/CCSlider.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ - (void) updateSliderPositionFromValue
7171
_handle.position = ccp(size.width * _sliderValue, size.height/2.0f);
7272
}
7373

74-
#if __CC_PLATFORM_IOS
74+
#if __CC_PLATFORM_IOS || __CC_PLATFORM_ANDROID
7575

7676
#pragma mark Handle touches
7777

cocos2d/CCDirector.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -740,7 +740,7 @@ -(void) resume
740740
{
741741
if( ! _isPaused )
742742
return;
743-
743+
744744
[self setAnimationInterval: _oldAnimationInterval];
745745

746746
if( gettimeofday( &_lastUpdate, NULL) != 0 ) {

cocos2d/CCNode.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,16 @@ A common user pattern in building a Cocos2d game is to subclass CCNode, add it t
615615
*/
616616
- (CGPoint)convertToWorldSpaceAR:(CGPoint)nodePoint;
617617

618+
/**
619+
* Converts a local Point to Window space coordinates.The result is in Points.
620+
* Treats the returned/received node point as anchor relative.
621+
*
622+
* @param nodePoint Local position in points.
623+
*
624+
* @return UI position in points.
625+
*/
626+
- (CGPoint)convertToWindowSpace:(CGPoint)nodePoint;
627+
618628

619629
/// -----------------------------------------------------------------------
620630
/// @name Rendering (Used by Subclasses)

cocos2d/Platforms/Android/CCActivity.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ BRIDGE_CLASS("org.cocos2d.CCActivity")
2424

2525
- (void)onDestroy;
2626

27+
- (void)onPause;
28+
- (void)onResume;
29+
2730
- (void)onLowMemory;
2831

2932
- (void)surfaceChanged:(JavaObject<AndroidSurfaceHolder> *)holder format:(int)format width:(int)width height:(int)height;

0 commit comments

Comments
 (0)