Cocos2D 2.0 screenshots on iOS 6

I am not sure what the GitHub version does but this code will take a screenshot and I just tested it on iOS 6 and it works fine.

+(UIImage*) screenshotWithStartNode:(CCNode*)startNode
{
    [CCDirector sharedDirector].nextDeltaTimeZero = YES;

    CGSize winSize = [CCDirector sharedDirector].winSize;
    CCRenderTexture* rtx = 
    [CCRenderTexture renderTextureWithWidth:winSize.width 
                                 height:winSize.height];
    [rtx begin];
    [startNode visit];
    [rtx end];

    return [rtx getUIImage];
}

You can call it like this

CCScene *scene = [[CCDirector sharedDirector] runningScene];
CCNode *n = [scene.children objectAtIndex:0];
UIImage *img = [AppController screenshotWithStartNode:n];

Leave a Comment