0

I'm very headache about this problem, I'm using these code for capturing a part of the screen

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

}

I can get my UIImage by

image = [self glToUIImage];

Then I try to use this code to generate a sprite by the 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];
}

I can get image by these code at first time, but after I changed the screen's contents and use these code to generate new sprite(new UIImage) with the new contents, I'm failed.... the image doesn't change to new image...

How can I get the new image sprite when every time I run the "imageSprite" code?

MikO
  • 18,243
  • 12
  • 77
  • 109

1 Answers1

0

You can get the new image sprite, but you must to change key

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

Liolik
  • 791
  • 6
  • 12
  • I try to use [NSString stringWithFormat:@"photoCap%d.png", userphotoCount] as the key, so when running -(UIImage *) glToUIImage the "userphotoCount++" can give a new number for photoCap%d.png Do you mean it's wrong? can you give me some suggestions? My purpose is: when everytime user tap a button, he can get the new sprite with new image – hkcitydancer May 30 '13 at 12:45