From 4e079240c007dc66460bf790b91a7e8186d43d69 Mon Sep 17 00:00:00 2001 From: Nader Eloshaiker Date: Sun, 15 Nov 2015 11:19:01 +1100 Subject: [PATCH 1/4] iOS 9 support for -(UIInterfaceOrientationMask)supportedInterfaceOrientations --- cocos2d/Platforms/iOS/CCAppDelegate.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cocos2d/Platforms/iOS/CCAppDelegate.m b/cocos2d/Platforms/iOS/CCAppDelegate.m index e1ac3549032..1ecea621aab 100644 --- a/cocos2d/Platforms/iOS/CCAppDelegate.m +++ b/cocos2d/Platforms/iOS/CCAppDelegate.m @@ -59,7 +59,7 @@ @implementation CCNavigationController // The available orientations should be defined in the Info.plist file. // And in iOS 6+ only, you can override it in the Root View controller in the "supportedInterfaceOrientations" method. // Only valid for iOS 6+. NOT VALID for iOS 4 / 5. --(NSUInteger)supportedInterfaceOrientations +-(UIInterfaceOrientationMask)supportedInterfaceOrientations { if ([_screenOrientation isEqual:CCScreenOrientationAll]) { @@ -123,7 +123,7 @@ @implementation CCAppDelegate @synthesize window=window_, navController=navController_; -- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window +- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { return UIInterfaceOrientationMaskAll; } From 3b5a548fe961994d5b4d435916cd8755debc03b8 Mon Sep 17 00:00:00 2001 From: Nader Eloshaiker Date: Mon, 23 Nov 2015 08:17:19 +1100 Subject: [PATCH 2/4] Support for -iphone6plus and -iphone6plushd suffixes. This allows for devs to specify different images (potentially screen backgrounds) for the iPad/iphone6+ rather than iPhone 6+ using either iPad or iphone5 assets. The iPad background images have the correct resolution for the iPhone 6+ but the wrong aspect ratio while iPhone 5 background images have the correct aspect ratio but the wrong resolution. --- cocos2d/Support/CCFileUtils.h | 2 ++ cocos2d/Support/CCFileUtils.m | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/cocos2d/Support/CCFileUtils.h b/cocos2d/Support/CCFileUtils.h index 1d82620881f..a945fb2f498 100644 --- a/cocos2d/Support/CCFileUtils.h +++ b/cocos2d/Support/CCFileUtils.h @@ -36,6 +36,8 @@ extern NSString * const CCFileUtilsSuffixiPhone; extern NSString * const CCFileUtilsSuffixiPhoneHD; extern NSString * const CCFileUtilsSuffixiPhone5; extern NSString * const CCFileUtilsSuffixiPhone5HD; +extern NSString * const CCFileUtilsSuffixiPhone6Plus; +extern NSString * const CCFileUtilsSuffixiPhone6PlusHD; extern NSString * const CCFileUtilsSuffixMac; extern NSString * const CCFileUtilsSuffixMacHD; diff --git a/cocos2d/Support/CCFileUtils.m b/cocos2d/Support/CCFileUtils.m index 626c323917d..43d4da7dc5b 100644 --- a/cocos2d/Support/CCFileUtils.m +++ b/cocos2d/Support/CCFileUtils.m @@ -39,6 +39,8 @@ NSString * const CCFileUtilsSuffixiPhoneHD = @"iphonehd"; NSString * const CCFileUtilsSuffixiPhone5 = @"iphone5"; NSString * const CCFileUtilsSuffixiPhone5HD = @"iphone5hd"; +NSString * const CCFileUtilsSuffixiPhone6Plus = @"iphone6plus"; +NSString * const CCFileUtilsSuffixiPhone6PlusHD = @"iphone6plushd"; NSString * const CCFileUtilsSuffixMac = @"mac"; NSString * const CCFileUtilsSuffixMacHD = @"machd"; NSString * const CCFileUtilsSuffix2x = @"2x"; @@ -163,6 +165,8 @@ -(id) init @"-hd", CCFileUtilsSuffixiPhoneHD, @"-iphone5", CCFileUtilsSuffixiPhone5, @"-iphone5hd", CCFileUtilsSuffixiPhone5HD, + @"-iphone6plus", CCFileUtilsSuffixiPhone6Plus, + @"-iphone6plushd", CCFileUtilsSuffixiPhone6PlusHD, @"", CCFileUtilsSuffixDefault, nil]; @@ -173,6 +177,8 @@ -(id) init @"resources-iphonehd", CCFileUtilsSuffixiPhoneHD, @"resources-iphone5", CCFileUtilsSuffixiPhone5, @"resources-iphone5hd", CCFileUtilsSuffixiPhone5HD, + @"resources-iphone6plus", CCFileUtilsSuffixiPhone6Plus, + @"resources-iphone6plushd", CCFileUtilsSuffixiPhone6PlusHD, @"", CCFileUtilsSuffixDefault, nil]; @@ -223,6 +229,8 @@ - (void) buildSearchResolutionsOrder [_searchResolutionsOrder addObject:CCFileUtilsSuffixiPadHD]; [_searchResolutionsOrder addObject:CCFileUtilsSuffixiPad]; if( _enableiPhoneResourcesOniPad ) { + [_searchResolutionsOrder addObject:CCFileUtilsSuffixiPhone6PlusHD]; + [_searchResolutionsOrder addObject:CCFileUtilsSuffixiPhone6Plus]; [_searchResolutionsOrder addObject:CCFileUtilsSuffixiPhone5HD]; [_searchResolutionsOrder addObject:CCFileUtilsSuffixiPhoneHD]; } @@ -240,6 +248,8 @@ - (void) buildSearchResolutionsOrder { // Terrible, terrible iPhone 6+ hack. [self setiPadContentScaleFactor:2.0]; + [_searchResolutionsOrder addObject:CCFileUtilsSuffixiPhone6PlusHD]; + [_searchResolutionsOrder addObject:CCFileUtilsSuffixiPhone6Plus]; [_searchResolutionsOrder addObject:CCFileUtilsSuffixiPadHD]; [_searchResolutionsOrder addObject:CCFileUtilsSuffixiPhone5HD]; From 01a0692204e16c3595ebc6f563610f1a307014aa Mon Sep 17 00:00:00 2001 From: Nader Eloshaiker Date: Mon, 23 Nov 2015 08:45:54 +1100 Subject: [PATCH 3/4] Set correct scale ratio for -iphone6plus and -iphone6plushd suffixes. --- cocos2d/Support/CCFileUtils.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cocos2d/Support/CCFileUtils.m b/cocos2d/Support/CCFileUtils.m index 43d4da7dc5b..ae04eaddd64 100644 --- a/cocos2d/Support/CCFileUtils.m +++ b/cocos2d/Support/CCFileUtils.m @@ -423,6 +423,10 @@ -(CGFloat) contentScaleForKey:(NSString*)k inDictionary:(NSDictionary *)dictiona return 1.0*_iPhoneContentScaleFactor; if( [key isEqualToString:CCFileUtilsSuffixiPhone5HD] ) return 2.0*_iPhoneContentScaleFactor; + if( [key isEqualToString:CCFileUtilsSuffixiPhone6PlusHD] ) + return 2.0*_iPadContentScaleFactor; + if( [key isEqualToString:CCFileUtilsSuffixiPhone6Plus] ) + return 1.0*_iPadContentScaleFactor; if( [key isEqualToString:CCFileUtilsSuffixDefault] ) return 1.0; #elif __CC_PLATFORM_MAC From ba2ca291c9d7aaeb0c83b8ec129437725656161b Mon Sep 17 00:00:00 2001 From: Nader Eloshaiker Date: Mon, 28 Dec 2015 18:07:00 +1100 Subject: [PATCH 4/4] CCProgressNode is now able to progress clockwise and anti-clockwise using the property "reverseRadial". --- cocos2d/CCProgressNode.h | 3 +++ cocos2d/CCProgressNode.m | 29 +++++++++++++++++++++++------ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/cocos2d/CCProgressNode.h b/cocos2d/CCProgressNode.h index 438fc288dc2..9e8c4764fc2 100644 --- a/cocos2d/CCProgressNode.h +++ b/cocos2d/CCProgressNode.h @@ -98,6 +98,9 @@ typedef NS_ENUM(NSUInteger, CCProgressNodeType) { /** Progress start position. */ @property (nonatomic, readwrite) CGPoint midpoint; +/** Radial Reverse Direction */ +@property (nonatomic, readwrite) BOOL reverseRadial; + /// ----------------------------------------------------------------------- /// @name Animating the Progress Node /// ----------------------------------------------------------------------- diff --git a/cocos2d/CCProgressNode.m b/cocos2d/CCProgressNode.m index 2f317d64be2..1635386de27 100644 --- a/cocos2d/CCProgressNode.m +++ b/cocos2d/CCProgressNode.m @@ -57,6 +57,7 @@ @implementation CCProgressNode { @synthesize sprite = _sprite; @synthesize type = _type; @synthesize reverseDirection = _reverseDirection; +@synthesize reverseRadial = _reverseRadial; @synthesize midpoint = _midpoint; @synthesize barChangeRate = _barChangeRate; @@ -76,6 +77,7 @@ -(id)initWithSprite:(CCSprite*) sprite if(( self = [super init] )){ _type = CCProgressNodeTypeRadial; _reverseDirection = NO; + _reverseRadial = NO; _percentage = 0.f; _verts = NULL; _vertexCount = 0; @@ -146,6 +148,15 @@ -(void)setReverseDirection:(BOOL)reverse } } +-(void)setReverseRadial:(BOOL)counterClockWise { + if(_reverseRadial != counterClockWise) { + _reverseRadial = counterClockWise; + + _dirtyVertexData = YES; + _needsUpdateProgress = YES; + } +} + -(void)setColor:(CCColor*)c { _sprite.color = c; @@ -259,10 +270,15 @@ -(void)setMidpoint:(CGPoint)midPoint } static inline CGPoint -BoundryTexCoord(int index) +BoundryTexCoord(int index, bool reverse) { - static const CGPoint points[] = {{1,1}, {1,0}, {0,0}, {0,1}}; - return points[index]; + if (!reverse) { + static const CGPoint points[] = {{1,1}, {1,0}, {0,0}, {0,1}}; + return points[index]; + } else { + static const CGPoint points[] = {{0,1}, {0,0}, {1,0}, {1,1}}; + return points[index]; + } } /// @@ -283,6 +299,7 @@ -(void)updateRadial float alpha = _percentage / 100.f; float angle = 2.f*((float)M_PI) * ( _reverseDirection == YES ? alpha : 1.f - alpha); + angle *= (_reverseRadial == YES) ? -1.f : 1.f; // We find the vector to do a hit detection based on the percentage // We know the first vector is the one @ 12 o'clock (top,mid) so we rotate @@ -314,8 +331,8 @@ -(void)updateRadial for (int i = 0; i <= 4; ++i) { int pIndex = (i + 3)%4; - CGPoint edgePtA = BoundryTexCoord(i % 4); - CGPoint edgePtB = BoundryTexCoord(pIndex); + CGPoint edgePtA = BoundryTexCoord(i % 4, _reverseRadial); + CGPoint edgePtB = BoundryTexCoord(pIndex, _reverseRadial); // Remember that the top edge is split in half for the 12 o'clock position // Let's deal with that here by finding the correct endpoints @@ -385,7 +402,7 @@ -(void)updateRadial _verts[1].position = [self vertexFromAlphaPoint:topMid]; for(int i = 0; i < index; ++i){ - CGPoint alphaPoint = BoundryTexCoord(i); + CGPoint alphaPoint = BoundryTexCoord(i, _reverseRadial); _verts[i+2].texCoord1 = [self textureCoordFromAlphaPoint:alphaPoint]; _verts[i+2].position = [self vertexFromAlphaPoint:alphaPoint]; }