实现CCLabelProtocol和CCRGBAProtocol是在命名为Label的类中:
#import@interface Label : CCNode
@property (nonatomic, copy, readwrite) NSString* string;
@property (nonatomic, readwrite) ccColor3B color;
@property (nonatomic, readwrite) GLubyte opacity;
- (id) initWithString: (NSString*) aString;
@end
还加了一个initWithString 方法:
#import “Label.h”
@implementation Label
@synthesize string,opacity,color;
- (id) initWithString: (NSString*) aString
{
if(self=)
{
string= aString;
color.r=255;
color.g=0;
color.b=0;
opacity= 10;
}
return self;
}
- (ccColor3B) color
{
return color;
}
@end
这是HelloWorldLayer init方法:
Label* label= initWithString: @“Start”];
CCMenuItemLabel* item= [CCMenuItemLabel itemWithLabel: label block:^(id sender)
{
NSLog(@"Label Clicked");
}];
CCMenu* menu= ;
;
<p> </p>
</p>
<p style="font:14px/24px Helvetica, Tahoma, Arial, sans-serif;list-style:none;margin:0px 0px 1em;padding:0px;text-align:left;color:#333333;text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;white-space:normal;orphans:2;widows:2;background-color:#ffffff;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;">
我用的是普通的cocos2d模板,放在CCLayer类中的。</p>
<p style="font:14px/24px Helvetica, Tahoma, Arial, sans-serif;list-style:none;margin:0px 0px 1em;padding:0px;text-align:left;color:#333333;text-transform:none;text-indent:0px;letter-spacing:normal;word-spacing:0px;white-space:normal;orphans:2;widows:2;background-color:#ffffff;-webkit-text-size-adjust:auto;-webkit-text-stroke-width:0px;">但是运行之后屏幕是黑的,没显示label。</p>