Created
July 17, 2010 17:42
-
-
Save mwhuss/479687 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // CocoasTools.h | |
| #define cts(p) [CocosTools scalePoint:(p)] | |
| #define cti(i) [CocosTools scaleImage:(i)] | |
| @interface CocosTools : NSObject { | |
| } | |
| + (CGFloat)scalePoint:(CGFloat)size; | |
| + (NSString *)scaleImage:(NSString *)image; | |
| @end | |
| // CocosTool.m | |
| #import "CocosTools.h" | |
| #import "CCDirector.h" | |
| @implementation CocosTools | |
| + (CGFloat)scalePoint:(CGFloat)size { | |
| CCDirector *director = [CCDirector sharedDirector]; | |
| [director contentScaleFactor]; | |
| if (director.contentScaleFactor == 2) { | |
| return size * 2; | |
| } else { | |
| return size; | |
| } | |
| } | |
| + (NSString *)scaleImage:(NSString *)imageName { | |
| CCDirector *director = [CCDirector sharedDirector]; | |
| [director contentScaleFactor]; | |
| if (director.contentScaleFactor == 2) { | |
| NSArray *chunks = [imageName componentsSeparatedByString:@"."]; | |
| return [NSString stringWithFormat:@"%@@2x.%@", [chunks objectAtIndex:0], [chunks objectAtIndex:1]]; | |
| } else { | |
| return imageName; | |
| } | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment