【问题标题】:Cocos2d Screen capture and get sprite from UIImageCocos2d 截屏并从 UIImage 获取 sprite
【发布时间】:2013-05-30 11:53:40
【问题描述】:

这个问题我很头疼,我正在使用这些代码来捕获屏幕的一部分

-(UIImage *) glToUIImage {

    userphotoCount++;
    [CCDirector sharedDirector].nextDeltaTimeZero = YES;

    CGSize winSize = [CCDirector sharedDirector].winSize;

    CCLayerColor* whitePage = [CCLayerColor layerWithColor:ccc4(255, 255, 255, 0) width:winSize.width height:winSize.height];
    whitePage.position = ccp(winSize.width/2, winSize.height/2);

    CCRenderTexture* rtx = [CCRenderTexture renderTextureWithWidth:815 height:532];
    [rtx begin];
    [whitePage visit];
    [[[CCDirector sharedDirector] runningScene] visit];
    [rtx end];

    return [rtx getUIImageFromBuffer];

}

我可以通过

获取我的 UIImage
image = [self glToUIImage];

然后我尝试使用此代码通过 UIImage 生成精灵

-(void) ImageSprite{

image = [self glToUIImage];
userAns =  [CCSprite spriteWithCGImage:image.CGImage key:[NSString stringWithFormat:@"photoCap%d.png", userphotoCount]];
    userAns.position=ccp(780,410);
    userAns.scale=0.6;
        [self addChild:userAns z:20];
}

我第一次可以通过这些代码获取图像,但是在我更改了屏幕的内容并使用这些代码用新内容生成新的 sprite(new UIImage) 之后,我失败了.... t 更改为新图像...

每次运行“imageSprite”代码时如何获取新的图像精灵?

【问题讨论】:

    标签: cocos2d-iphone uiimage screen sprite capture


    【解决方案1】:

    你可以得到新的图像精灵,但你必须改变键

    [CCSprite spriteWithCGImage:image.CGImage key:key];

    【讨论】:

    • 我尝试使用 [NSString stringWithFormat:@"photoCap%d.png", userphotoCount] 作为键,因此在运行 -(UIImage *) glToUIImage 时,“userphotoCount++”可以为photoCap%d.png 你的意思是错了吗?你能给我一些建议吗?我的目的是:当用户每次点击按钮时,他都可以获得带有新图像的新精灵
    猜你喜欢
    • 1970-01-01
    • 2012-05-28
    • 2013-11-18
    • 1970-01-01
    • 1970-01-01
    • 2014-02-01
    • 2017-12-09
    • 1970-01-01
    • 2011-11-14
    相关资源
    最近更新 更多