我有一个应用程序可以截取场景的屏幕截图并将其保存到文件中。我有这个工作,应用程序在商店里。今天,我下载了 iOS 6,但我使用的方法不再有效。我测试了所有我知道的让它工作的东西,用谷歌搜索并找到了这个:
http://www.cocos2d-iphone.org/forum/topic/37809?replies=22#post-180983
用户似乎同意这适用于 iOS 5,但我已经在 iOS 6 上测试过它并生成黑色屏幕截图。
我不是 Cocos2D 方面的专家,所以我不能确切地说出这个人的代码有什么问题。作者在 github 上有一个示例项目,甚至他的项目也在 iOS 6 上生成黑色屏幕截图。
有什么线索吗?谢谢。
谢谢
最佳答案
我不确定 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];
}
你可以这样调用它
CCScene *scene = [[CCDirector sharedDirector] runningScene];
CCNode *n = [scene.children objectAtIndex:0];
UIImage *img = [AppController screenshotWithStartNode:n];
关于iphone - iOS 6 上的 Cocos2D 2.0 截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12413460/