Skip to content

Instantly share code, notes, and snippets.

@Seasons7
Created January 14, 2011 12:05
Show Gist options
  • Save Seasons7/779525 to your computer and use it in GitHub Desktop.
Save Seasons7/779525 to your computer and use it in GitHub Desktop.
CCSprite+hd.m
@interface CCSprite ( hd )
+(id)spriteWithSpriteFrameName:(NSString*)spriteFrameName;
@end
@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