Cocos2D 2.0 screenshots on iOS 6

前端 未结 4 923
灰色年华
灰色年华 2020-12-03 18:56

I have an application that takes a screenshot of a scene and saves it to a file. I have this working and the application is on the store. Today, I have downloaded iOS 6 and

相关标签:
4条回答
  • 2020-12-03 19:20

    This here works for 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];
    }
    
    0 讨论(0)
  • 2020-12-03 19:21

    I am not sure what the GitHub version does but this code will take a screenshot and I just tested it on iOS 6 and it works fine.

    +(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];
    }
    

    You can call it like this

    CCScene *scene = [[CCDirector sharedDirector] runningScene];
    CCNode *n = [scene.children objectAtIndex:0];
    UIImage *img = [AppController screenshotWithStartNode:n];
    
    0 讨论(0)
  • 2020-12-03 19:29

    Above 2 answers not worked in Cocos2d 3.2.1

    Here is Solution for 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];
    
    0 讨论(0)
  • 2020-12-03 19:29

    The top answer works for iPads (I have tested on iPads v1 thru 4).

    It does NOT work for the actual device: iPhone5, iOS7.

    However, it does work for simulators of such an iPhone 5!

    That inconsistency is driving me crazy!

    0 讨论(0)
提交回复
热议问题