有时候为了方便需要是不是需要把UIImage转换成精灵 ,而有时候又需要把精灵转换成UIImage, 有木有为这些在烦恼的,有的话顶起来-(CCSprite *) convertImageToSprite:(UIImage *) image {
CCTexture2D *texture = [[CCTexture2D alloc] initWithImage:image];
CCSprite *sprite = [CCSprite spriteWithTexture:texture];
[texture release];
return sprite;
}
-(UIImage *) convertSpriteToImage:(CCSprite *)sprite {
CGPoint p = sprite.anchorPoint;
[sprite setAnchorPoint:ccp(0,0)];
CCRenderTexture *renderer = [CCRenderTexture renderTextureWithWidth:sprite.contentSize.width height:sprite.contentSize.height];
[renderer begin];
[sprite visit];
[renderer end];
[sprite setAnchorPoint:p];
return [UIImage imageWithData:[renderer getUIImageAsDataFromBuffer:kCCImageFormatPNG]];
}