【发布时间】:2011-03-03 22:41:12
【问题描述】:
我有一个方法可以拆分 UIImage 并将图像的各个部分作为数组返回:
- (NSMutableArray *) splitImage:(UIImage *)image;
但我需要将 Cocos2d 精灵分成两半。如何从精灵中获取 UIImage?
我能找到的最接近的是精灵的 CCTexture2D,但我仍然无法找到 UIImage。
【问题讨论】:
标签: cocos2d-iphone uiimage sprite
我有一个方法可以拆分 UIImage 并将图像的各个部分作为数组返回:
- (NSMutableArray *) splitImage:(UIImage *)image;
但我需要将 Cocos2d 精灵分成两半。如何从精灵中获取 UIImage?
我能找到的最接近的是精灵的 CCTexture2D,但我仍然无法找到 UIImage。
【问题讨论】:
标签: cocos2d-iphone uiimage sprite
不幸的是,CCTextureCache 在实例化 CCTexture2D 时不保留任何图像(UIImage、PNG、JPEG 等)。它使用 glTexImage2D 或 glCompressedTexImage2D 使用图像数据创建 OpenGL ES 纹理,但是应用程序无法访问纹理的像素数据。 CCTexture2D 也不保留任何图像。
因此,您必须保留从 CCSprite 使用的 CCTexture2D 的 UIImage 实例。
【讨论】:
创建一个保留纹理名称的 CCSprite 子类。不仅仅是加载图像来创建 UIImage(当然需要额外加载,但这是一种解决方案)。
【讨论】: