我有一个应用程序,它截取场景的屏幕截图并将其保存到文件中。我有这个工作,应用程序在商店。今天,我已经下载了iOS 6,我正在使用的方法不再适用了。我测试了所有我知道的工作,用Google搜索并发现了这个:
http://www.cocos2d-iphone.org/forum/topic/37809?replies=22#post-180983
用户似乎同意这适用于iOS 5,但我已经在iOS 6上进行了测试,并且它正在生成黑色屏幕截图。
我不是Cocos2D的专家,所以我不能确切地说这个人的代码有什么问题。作者在github上有一个示例项目,甚至他的项目也在iOS 6上制作黑色截图。
任何线索?感谢。
感谢
答案 0 :(得分: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];
}
你可以这样称呼它
CCScene *scene = [[CCDirector sharedDirector] runningScene];
CCNode *n = [scene.children objectAtIndex:0];
UIImage *img = [AppController screenshotWithStartNode:n];
答案 1 :(得分:2)
这适用于Cocos2d V3。
+(UIImage*) screenshotWithStartNode:(CCNode*)startNode
{
[CCDirector sharedDirector].nextDeltaTimeZero = YES;
CGSize viewSize = [[CCDirector sharedDirector] viewSize];
CCRenderTexture* rtx =
[CCRenderTexture renderTextureWithWidth:viewSize.width
height:viewSize.height];
[rtx begin];
[startNode visit];
[rtx end];
return [rtx getUIImage];
}
答案 2 :(得分:0)
以上2个答案在Cocos2d 3.2.1
中无效这是Cocos2d 3.2.1 +
的解决方案-(UIImage*) takePresentScreenshot
{
[CCDirector sharedDirector].nextDeltaTimeZero = YES;
CGSize size = [[CCDirector sharedDirector] viewSize];
CCRenderTexture *renderTxture = [CCRenderTexture renderTextureWithWidth:size.width
height:size.height];
[renderTxture begin];
[[[CCDirector sharedDirector] runningScene] visit];
[renderTxture end];
return [renderTxture getUIImage];
}
UIImage* screenshot = [self takePresentScreenshot];
答案 3 :(得分:0)
最佳答案适用于iPad(我已在iPad v1至4上测试过)。
它不适用于实际设备:iPhone5,iOS7。
但是,它适用于iPhone 5的模拟器!
这种不一致让我发疯了!