如何在applicationDidEnterBackground上检测/工作完全透明的屏幕截图?

时间:2014-07-16 23:07:08

标签: cocos2d-iphone screenshot multitasking

我使用这段代码在applicationDidEnterBackground上保存屏幕截图,后者在后台加载场景时显示为加载屏幕。

@implementation CCDirector(ScreenShot)

+(void)saveScreenshotWithFilename: (NSString*) filename {
    [CCDirector sharedDirector].nextDeltaTimeZero = YES;

    CGSize winSize = CCDirector.sharedDirector.winSize;
    CCRenderTexture * renderTexture = [CCRenderTexture renderTextureWithWidth:winSize.width
                                                                       height:winSize.height
                                                                  pixelFormat:kCCTexture2DPixelFormat_RGBA8888
                                                           depthStencilFormat:GL_DEPTH_COMPONENT16];

    [renderTexture beginWithClear:0 g:0 b:0 a:0 depth:1.0f];
    [CCDirector.sharedDirector.runningScene visit];
    [renderTexture end];

    UIImage *image = [renderTexture getUIImage];

    NSString *filePath = [[[NSBundle mainBundle] bundlePath] stringByAppendingFormat:@"/%@", filename];

    [UIImagePNGRepresentation(image) writeToFile:filePath atomically:YES];
}

@end

它工作正常,但是当用户点击应用程序图标以运行应用程序时,然后点击主页按钮,然后再次快速点击应用程序图标,生成的屏幕截图是一个透明的PNG文件,正确的尺寸,但完全透明。

如何检查此特殊情况以将其他图像显示为加载屏幕?

......或者更好的是,透明屏幕截图有解决方法吗?

0 个答案:

没有答案