cocos2d – take a screenshot
How to make a screenshot with cocos2d 2.0 and CCRenderTexture:
-(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.
Recent Comments