hi,
i tryed to create a own GUI component with cocos 2d... i haved written a class (extends Sprite) ... this class initialize with graphics and a lable... if I create an instance of my class .. i can see my component but i can user any functions... i wrote a setLabel function .. but the lable change...
i create a instance with this code:
drop1 = [DropDown init];
//here I call the function but it dont works :-(
[drop1 setCaption:@"Produkt"];
///dropDown.m:
#import "DropDown.h"
@implementation DropDown
@synthesize captionLbl;
+ (id) init
{
if( (self=[super init] ))
{
return [[[self spriteWithFile:@"menue_dropdownbtn.png"] addChild:[[self alloc] initActiveState]] addChild:[[self alloc] initLabel]];
}
}
- (id)initActiveState
{
activated = [Sprite spriteWithFile:@"menue_dropactiveated.png"];
[activated setAnchorPoint:ccp(0,0)];
[activated setPosition:ccp(173,0)];
[activated setVisible:NO];
return activated;
}
- (id)initLabel
{
captionLbl = [Label labelWithString:@"Text" fontName:@"Arial" fontSize:14.0f];
[captionLbl setAnchorPoint:ccp(0,0)];
[captionLbl setPosition:ccp(10,5)];
[captionLbl setRGB:0 :0 :0];
return captionLbl;
}
- (void)setCaption:(NSString*)text
{
[captionLbl setString:text];
NSLog(@"Hallooooo");
}
- (void)activate
{
[activated setVisible:YES];
isActive = YES;
}
- (void)deactivate
{
[activated setVisible:NO];
isActive = NO;
}
@end
// DropDown.h
//
//
#import <Foundation/Foundation.h>
#import "cocos2d.h"
@interface DropDown : Sprite
{
BOOL isActive;
@private
Sprite* activated;
Label* captionLbl;
}
@property (nonatomic, retain) Label* captionLbl;
+ (id) init;
- (id)initActiveState;
- (id)initLabel;
- (void)setCaption:(NSString*)text;
- (void)activate;
- (void)deactivate;
@end