Created
January 14, 2011 12:05
-
-
Save Seasons7/779525 to your computer and use it in GitHub Desktop.
CCSprite+hd.m
This file contains 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
@interface CCSprite ( hd ) | |
+(id)spriteWithSpriteFrameName:(NSString*)spriteFrameName; | |
@end |
This file contains 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
@implementation CCSprite ( hd ) | |
+(id)spriteWithSpriteFrameName:(NSString*)spriteFrameName | |
{ | |
CCSpriteFrame *frame = nil; | |
if( CC_CONTENT_SCALE_FACTOR() == 2 ) { | |
// Add "-hd" suffix | |
NSRange range = [spriteFrameName rangeOfString:CC_RETINA_DISPLAY_FILENAME_SUFFIX]; | |
if( range.location == NSNotFound ) { | |
NSRange range = [spriteFrameName rangeOfString:@"."]; | |
if( range.location != NSNotFound ) { | |
NSString *baseName = [spriteFrameName substringToIndex:range.location]; | |
NSString *extension = [spriteFrameName substringFromIndex:range.location]; | |
NSString *newLastname = [baseName stringByAppendingFormat:[NSString stringWithFormat:@"%@%@",CC_RETINA_DISPLAY_FILENAME_SUFFIX,extension]]; | |
frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:newLastname]; | |
if( frame == nil ) | |
frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:spriteFrameName]; | |
return [self spriteWithSpriteFrame:frame]; | |
} | |
} | |
} | |
frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:spriteFrameName]; | |
return [self spriteWithSpriteFrame:frame]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment