iphone - iOs (cocos2d) 屏幕截图缓存或 CCRenderTexture 缓冲区?它没有改变

标签 iphone ios cocos2d-iphone

我使用这个问题的提示 stackoverflow.com/questions/12413460 是工作。我的问题是图像没有刷新,而应用程序没有重新启动或没有重建。 我使用创建屏幕截图的方法。我有什么相同的功能:使用触摸屏,屏幕截图将保存到文档目录中。用户触摸第二个,第二个屏幕截图保存。所以。但是在我的应用程序中,每次只创建第一次触摸屏幕截图,因为它被缓存或缓冲了。

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

我在用户触摸屏幕时调用它(例如)

- (void)ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    CCNode *n = [[[CCDirector sharedDirector] runningScene].children objectAtIndex:0];
    UIImage *img = [self screenshotWithStartNode:n];//this image always same by one, same when user touch screen first time
    CCSprite *spriteTemp = [CCSprite spriteWithCGImage:img.CGImage key:@"image"];
    [self addChild:spriteTemp];
}

屏幕上的项目在时间上有不同的位置。 第一次触摸屏幕获得正确的图像。但所有其他触摸创建屏幕截图作为第一张图像并且不会改变。

我想也许是缓冲区 CCRenderTexture?或图像缓存?我会做什么?

我尝试 [img release] 并在触摸后尝试 CGImageRelease(img.CGImage),但应用程序崩溃了。

最佳答案

没错,之前的信息都被缓存了。试试看

[[CCTextureCache sharedTextureCache] removeTextureForKey:@"image"];

在你尝试覆盖之前。

或者如果您同时需要多个图像,则使用不同的键名。

关于iphone - iOs (cocos2d) 屏幕截图缓存或 CCRenderTexture 缓冲区?它没有改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12439164/

相关文章:

iphone - 地幔 :cannot find protocol declaration, 'MTLJSONSerializing'

iphone - 通过应用内购买支付实体产品费用

具有逻辑的 iOS 启动屏幕

ios - 如何在 Cocos2d 中拉直行尾?

ios - 将图像添加到 navigationItem 的标题

ios - 如何在 iOS webview 的多个页面中注入(inject)/评估 JS?

ios - 如何在 iOS 锁定屏幕上添加搜索按钮?

objective-c - 方法 "shouldChangeTextInRange"和 "stringByReplacingCharactersInRange"是如何工作的?

iphone - 当我使用 resumeSchedulerAndActions 时 Sprite 跳来跳去

ios - CCSprite:批处理的 Sprite 应该使用与批处理节点相同的纹理?