1

I want to take a screen shot using the following command but it gives me warning and did not worked for me. I am using cocos2d version 2.0

UIImage *image = [[CCDirector sharedDirector] screenshotUIImage];

Please suggest me that what is the solution of that command so that it works perfectly.

Maulik
  • 19,348
  • 14
  • 82
  • 137
Matt
  • 139
  • 12
  • @Manthan He posted the code – Andrey Gordeev Nov 01 '13 at 06:20
  • 4
    Put some efforts by searching on net before asking question here – Maulik Nov 01 '13 at 06:21
  • I have tried to capture the whole screen and just run that code on a button press... Basically i want to capture the screen for sharing purpose. I have convert UIImage to CCSprite to crop that image. As, I did not get the image thats why i can't do any further process on that. – Matt Nov 01 '13 at 06:27
  • UIImage *image = [[CCDirector sharedDirector] screenshotUIImage]; This has been depricated. I think mod should lock this one. Its not useful anymore. – Alok C Sep 12 '15 at 03:00

1 Answers1

5

Create a method and use it as shown below

You can use this.

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

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

    return [renTxture getUIImage];
}

Call like this

CCScene *myScene = [[CCDirector sharedDirector] runningScene];
CCNode *node = [myScene.children objectAtIndex:0];
UIImage *img = [AppController screenshotWithStartNode:node];
Jay Gajjar
  • 2,661
  • 2
  • 21
  • 35
  • 1
    copy-paste of http://stackoverflow.com/questions/12413460/cocos2d-2-0-screenshots-on-ios-6. Prefer giving credit where credit is due. – YvesLeBorg Nov 01 '13 at 11:07
  • had used this code months ago not copy - pase... Yeah it took efforts finding the code & editing for better understand. – Jay Gajjar Nov 01 '13 at 11:51
  • CCDirector is deprocated. I am using Director but I am getting error that its not objective C class. :/ any clue – Alok C Aug 25 '15 at 01:41