Skip to content

Instantly share code, notes, and snippets.

@psineur
Created March 10, 2011 18:53
Show Gist options
  • Save psineur/864652 to your computer and use it in GitHub Desktop.
Save psineur/864652 to your computer and use it in GitHub Desktop.
CCMenuItemSprite for CCSpriteBatchNode
// CCMenuItemSpriteIndependent is CCMenuItemSprite that doesn't add normal, selected
// and disabled images as children. Instead of that its just retain them.
// So you can place images anyhow you want.
//
// Note: content size will be set from normalImage_ on init in CCMenuItemSprite
// CCMenuItemSpriteIndependent changes only the way of holding images
@interface CCMenuItemSpriteIndependent : CCMenuItemSprite
@end
@implementation CCMenuItemSpriteIndependent
-(void) setNormalImage:(CCNode <CCRGBAProtocol>*)image
{
if( image != normalImage_ ) {
//
[normalImage_ release];
//image.anchorPoint = ccp(0,0);
image.visible = YES;
//[self removeChild:normalImage_ cleanup:YES];
//[self addChild:image];
//normalImage_ = image;
normalImage_ = [image retain];
}
}
-(void) setSelectedImage:(CCNode <CCRGBAProtocol>*)image
{
if( image != selectedImage_ ) {
//
[selectedImage_ release];
//image.anchorPoint = ccp(0,0);
image.visible = NO;
//[self removeChild:selectedImage_ cleanup:YES];
//[self addChild:image];
//selectedImage_ = image;
selectedImage_ = [image retain];
}
}
-(void) setDisabledImage:(CCNode <CCRGBAProtocol>*)image
{
if( image != disabledImage_ ) {
//
[disabledImage_ release];
//image.anchorPoint = ccp(0,0);
image.visible = NO;
//[self removeChild:disabledImage_ cleanup:YES];
//[self addChild:image];
//disabledImage_ = image;
disabledImage_ = [image retain];
}
}
- (void) dealloc
{
[normalImage_ release];
[selectedImage_ release];
[disabledImage_ release];
[super dealloc];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment