I want to make a CCMenuItemImage with a UIImage. How should I do that?
You can create CCSprite to use it in CCMenuItemSprite with
+(id) spriteWithCGImage: (CGImageRef)image key:(NSString*)key;
constructor.
To get UIImage
object has CGImage
property, that returns CGImageRef
.
You can make CCSprite from UIImage using this code:
CCTexture2D *tex = [[[CCTexture2D alloc] initWithImage:uiImage] autorelease];
CCSprite *sprite1 = [CCSprite spriteWithTexture:tex];
After creating CCSprite you can make CCMenuItem using code:
CCMenuItem *mnItem = [CCMenuItemSprite itemFromNormalSprite:sprite1 selectedSprite:sprite1 disabledSprite:sprite1 target:self selector:@selector(yourSelector:)];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.