本文介绍了如何将 CCSprite 图像转换为 UIImage?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

作为标题,我已经提到了下面的代码

As the title, I have mentioned the code below

CCSprite *sprite = (CCSprite *)node;
CCTexture2D *texture2d = [sprite texture];

如何从 sprite 中获取 UIImage *p?

How can I get a UIImage *p from sprite?

推荐答案

在你的情况下,只需将下一个方法添加到你的类中:

In your case just add next methood into your class:

 - (UIImage *) imageFromSprite :(CCSprite *)sprite
{
    int tx = sprite.contentSize.width;
    int ty = sprite.contentSize.height;

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

    sprite.anchorPoint  = CGPointZero;

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

    return [renderer getUIImage];
}

使用方法:

CCSprite *sprite = (CCSprite *)node;
UIImage *p = [self imageFromSprite:sprite]

这篇关于如何将 CCSprite 图像转换为 UIImage?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-10 17:27