ios6上cocos2d截屏失效有关问题处理
ios6下cocos2d截屏失效问题处理
相信使用cocos2d官方论坛提供的截屏方法,或者其他使用openGL方式截屏的同志们,会发现在iOS6系统的真机上截图为全黑色,但是在其他版本系统的真机上没问题,而且在模拟器上也没问题,包括iOS6的模拟器。网上狂搜了一把,解决方案如下:
第一种:设置GLView的preserveBackbuffer属性值为YES:
在AppDelegate.m文件中找到:
EAGLView *glView = [EAGLView viewWithFrame:[window bounds] pixelFormat:kEAGLColorFormatRGB565 // kEAGLColorFormatRGBA8 depthFormat:0 // GL_DEPTH_COMPONENT16_OES ];
将其修改为:
EAGLView *glView = [EAGLView viewWithFrame:[window bounds] pixelFormat:kEAGLColorFormatRGB565 // kEAGLColorFormatRGBA8 depthFormat:0 // GL_DEPTH_COMPONENT16_OES preserveBackbuffer:YES sharegroup:nil multiSampling:NO numberOfSamples:0 ];
第二种:使用以下一种截屏函数:
+(UIImage*) makeaShot { [CCDirector sharedDirector].nextDeltaTimeZero = YES; CGSize winSize = [CCDirector sharedDirector].winSize; CCLayerColor* whitePage = [CCLayerColor layerWithColor:ccc4(255, 255, 255, 0) width:winSize.width height:winSize.height]; whitePage.position = ccp(winSize.width/2, winSize.height/2); CCRenderTexture* rtx = [CCRenderTexture renderTextureWithWidth:winSize.width height:winSize.height]; [rtx begin]; [whitePage visit]; [[[CCDirector sharedDirector] runningScene] visit]; [rtx end]; return [rtx getUIImageFromBuffer]; }
-(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]; } CCScene *scene = [[CCDirector sharedDirector] runningScene]; CCNode *n = [scene.children objectAtIndex:0]; UIImage *img = [self screenshotWithStartNode:n];
参考链接:
http://www.cocos2d-iphone.org/forum/topic/40858
http://www.cocos2d-iphone.org/forum/topic/1722/page/4
http://*.com/questions/12413460/cocos2d-2-0-screenshots-on-ios-6
http://bentrengrove.com/blog/2012/10/23/taking-screenshots-in-cocos2d-on-ios6
http://www.cocos2d-iphone.org/forum/topic/37809