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://stackoverflow.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


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值