cocos2d – take a screenshot

  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

How to make a screenshot with cocos2d 2.0 and CCRenderTexture:

IMG_0257-sd

-(UIImage*) takeScreenShot
{
  [CCDirector sharedDirector].nextDeltaTimeZero = YES;
  CGSize winSize = [CCDirector sharedDirector].winSize;

  CCLayerColor* blankLayer = [CCLayerColor layerWithColor:ccc4(255, 255, 255, 0) width:winSize.width height:winSize.height];

  blankLayer.position = ccp(winSize.width/2, winSize.height/2);

  CCRenderTexture* rtx = [CCRenderTexture renderTextureWithWidth:winSize.width height:winSize.height];

  [rtx begin];
  [blankLayer visit];
  [[[CCDirector sharedDirector] runningScene] visit];
  [rtx end];

return [rtx getUIImage];

}

Instead of [[[CCDirector sharedDirector] runningScene] visit] , you can call only what you want to capture, ccnode, ccsprites, etc, You can also remove the white background layer, or set it transparent.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>