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
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];
}
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];
Above 2 answers not worked in Cocos2d 3.2.1
Here is Solution for Cocos2d 3.2.1 +
-(UIImage*) takePresentScreenshot
{
[CCDirector sharedDirector].nextDeltaTimeZero = YES;
CGSize size = [[CCDirector sharedDirector] viewSize];
CCRenderTexture *renderTxture = [CCRenderTexture renderTextureWithWidth:size.width
height:size.height];
[renderTxture begin];
[[[CCDirector sharedDirector] runningScene] visit];
[renderTxture end];
return [renderTxture getUIImage];
}
UIImage* screenshot = [self takePresentScreenshot];
The top answer works for iPads (I have tested on iPads v1 thru 4).
It does NOT work for the actual device: iPhone5, iOS7.
However, it does work for simulators of such an iPhone 5!
That inconsistency is driving me crazy!