我从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];
答案 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];