当前位置:编程学习 > wap >>

coco2d教程——sprite与UIImage的转换

+(UIImage *) convertSpriteToImage:(CCSprite *)sprite { 

02         CGPoint p = sprite.anchorPoint; 

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

04          

05         CCRenderTexture *renderer = [CCRenderTexture renderTextureWithWidth:sprite.contentSize.width height:sprite.contentSize.height]; 

06          

07         [renderer begin]; 

08         [sprite visit]; 

09         [renderer end]; 

10          

11       [sprite setAnchorPoint:p]; 

12          

13        return [UIImage imageWithData:[renderer getUIImageAsDataFromBuffer:kCCImageFormatPNG]]; 

14 }


使用CCRenderTexture将CCSprite转化为UIImage,将该函数写成UIImage的类别(catogery)
UIImage+Sprite.h
view sourceprint?1 #import <Foundation/Foundation.h> 

2 #import "cocos2d.h" 

3    

4 @inte易做图ce UIImage (Sprite) 

5    

6 + (UIImage *)convertSpriteToImage:(CCSprite *)sprite; 

7    

8 @end

UIImage+Sprite.m
view sourceprint?#import "UIImage+Sprite.h" 

  

@implementation UIImage (Sprite) 

   

+ (UIImage *)convertSpriteToImage:(CCSprite *)sprite {...} 

   

@end

 

补充:移动开发 , 其他 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,