首页新闻招聘找找看知识库
  • 浏览:1808 2012-11-02 13:29 来自 泪啸

    +(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]];
       }
      //使用CCRenderTexture将CCSprite转化为UIImage,将该函数写成UIImage的类别(catogery)
      UIImage+Sprite.h
      #import <Foundation/Foundation.h>
       #import "cocos2d.h"
      
       @interface UIImage (Sprite)
      
       + (UIImage *)convertSpriteToImage:(CCSprite *)sprite;
     
       @end
      //UIImage+Sprite.m#import "UIImage+Sprite.h"
      @implementation UIImage (Sprite)
      + (UIImage *)convertSpriteToImage:(CCSprite *)sprite {...}
      @end

登录后才能评论,请先登录注册