Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cocos2D 2.0 screenshots on iOS 6

I have an application that takes a screenshot of a scene and saves it to a file. I have this working and the application is on the store. Today, I have downloaded iOS 6 and the method I am using is not working anymore. I tested all I know to make it work, googled around and found this:

http://www.cocos2d-iphone.org/forum/topic/37809?replies=22#post-180983

Users seem to agree that this is working on iOS 5, but I have tested this on iOS 6 and it is producing black screenshots.

I am not a specialist in Cocos2D so, I cannot say exactly what is wrong with this guy's code. the author has a sample project on github and even his project is producing black screenshots on iOS 6.

Any clues? Thanks.

thanks

like image 918
Duck Avatar asked Sep 13 '12 19:09

Duck


2 Answers

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];
like image 151
Ben Trengrove Avatar answered Oct 16 '22 07:10

Ben Trengrove


This here works for Cocos2d V3.

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

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

    return [rtx getUIImage];
}
like image 2
Herman Avatar answered Oct 16 '22 09:10

Herman