Skip to content

Instantly share code, notes, and snippets.

@fictorial
Created May 15, 2012 04:45
Show Gist options
  • Save fictorial/2699203 to your computer and use it in GitHub Desktop.
Save fictorial/2699203 to your computer and use it in GitHub Desktop.
cocos2d-iphone screenshots
#import "cocos2d.h"
@interface CCScreenshot: NSObject
+ (NSString *)screenshotPathForFile:(NSString *)file;
+ (CCRenderTexture *)screenshotWithStartNode:(CCNode*)startNode filename:(NSString*)filename;
@end
#import "CCScreenshot.h"
@implementation CCScreenshot
+ (NSString *)screenshotPathForFile:(NSString *)file {
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths objectAtIndex:0];
NSString* screenshotPath = [documentsDirectory stringByAppendingPathComponent:file];
return screenshotPath;
}
+ (CCRenderTexture *)screenshotWithStartNode:(CCNode*)startNode filename:(NSString*)filename {
[CCDirector sharedDirector].nextDeltaTimeZero = YES;
CGSize winSize = [CCDirector sharedDirector].winSize;
CCRenderTexture* rtx = [CCRenderTexture renderTextureWithWidth:winSize.width height:winSize.height];
[rtx begin];
[startNode visit];
[rtx end];
[rtx saveBuffer:[self screenshotPathForFile:filename] format:kCCImageFormatPNG];
return rtx;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment