iOS 6上的Cocos2D 2.0截图

Spa*_*Dog 7 iphone cocos2d-iphone ipad ios

我有一个应用程序,它截取一个场景的截图并将其保存到文件中.我有这个工作,应用程序在商店.今天,我已经下载了iOS 6,我正在使用的方法不再适用了.我测试了所有我知道的工作,谷歌搜索并发现:

http://www.cocos2d-iphone.org/forum/topic/37809?replies=22#post-180983

用户似乎同意这适用于iOS 5,但我已经在iOS 6上进行了测试,并且它正在制作黑色屏幕截图.

我不是Cocos2D的专家所以,我不能确切地说这个人的代码有什么问题.作者在github上有一个示例项目,甚至他的项目也在iOS 6上制作黑色截图.

有线索吗?谢谢.

谢谢

Ben*_*ove 33

我不确定GitHub版本是做什么的,但是这段代码将截取屏幕截图,我只是在iOS 6上测试它,它工作正常.

+(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];
}
Run Code Online (Sandbox Code Playgroud)

你可以这样称呼它

CCScene *scene = [[CCDirector sharedDirector] runningScene];
CCNode *n = [scene.children objectAtIndex:0];
UIImage *img = [AppController screenshotWithStartNode:n];
Run Code Online (Sandbox Code Playgroud)