objective-ccocos2d-iphoneuiimagecctexturecache

UIImage to CCSprite cocos2d v 2.0


Moved to version 2.0 of Cocos2D but I'm trying to find a workaround solution to convert UIImage to CCSprite, previous one like:

        CCTexture2D *texture = [[[CCTexture2D alloc] initWithImage:tempImage] autorelease];
        self.spriteImage = [CCSprite spriteWithTexture:texture];

Note:

tempImage is a UIImage object


Solution

  • Try this:

    self.spriteImage = [[CCSprite alloc] initWithCGImage:tempImage.CGImage 
                                                     key:@"unique image name"];
    

    Alternatively there's also a initWithCGImage method in CCTexture2D if you prefer to use that.