如何从Cococ2d v2.1中的CCSprite中提取图像

时间:2014-03-26 07:08:23

标签: ios cocos2d-iphone cocos2d-iphone-2.x

我从Cocos2d v2.1中的CCSprite中提取图像。我已经获得了提取图像的参考,但它是空白的。

代码如下:

CCSprite *tile=[grass tileAt:CGPointMake(4 ,18 )];

int tx = tile.contentSize.width;
int ty = tile.contentSize.height;

CCRenderTexture *renderer = [CCRenderTexture renderTextureWithWidth:tx height:ty];

[sprite setAnchorPoint:ccp(0,0)];

[renderer begin];
[sprite visit];
[renderer end];

UIImage *img=[renderer getUIImageFromBuffer];

1 个答案:

答案 0 :(得分:0)

试试这个:

CCRenderTexture *renderer = [CCRenderTexture renderTextureWithWidth:tx height:ty pixelFormat:kCCTexture2DPixelFormat_RGBA8888 depthStencilFormat:GL_DEPTH24_STENCIL8];

    [renderer beginWithClear:0 g:0 b:0 a:0 depth:1.0f];
    [sprite visit];
    [renderer end];
    UIImage *img = [renderer getUIImage];