ioscocos2d-iphonecclabelttf

constructor of CCLabelTTF in cocos2d v3.0


I read this document and declare like that:

CCLabelTTF *label = [CCLabelTTF initWithString: @"a" fontName: @"HelveticaNeue" fontSize: 24 dimensions: CGSizeMake(320,480) hAlignment: CCVerticalTextAlignmentTop];

but its show warning: no know class method for selector... anybody can help me?


Solution

  • In Cocos2d V3, the cclabelTTF is changed. The available methods in CCLabelTTF.m are only:

    + (id) labelWithString:(NSString *)string fontName:(NSString *)name fontSize:    (CGFloat)size
     {
       return [[self alloc] initWithString:string fontName:name fontSize:size];
     }
    
     + (id) labelWithString:(NSString *)string fontName:(NSString *)name fontSize:(CGFloat)size dimensions:(CGSize)dimensions
     {
         return [[self alloc] initWithString:string fontName:name fontSize:size dimensions:dimensions];
     }
    
    + (id) labelWithAttributedString:(NSAttributedString *)attrString
    {
        return [[self alloc] initWithAttributedString:attrString];
    }
    
     + (id) labelWithAttributedString:(NSAttributedString *)attrString dimensions:(CGSize)dimensions
     {
         return [[self alloc] initWithAttributedString:attrString dimensions:dimensions];
     }
    

    So your implementation is not correct in COCOS2d V3. That is valid for V2 version. I think still document needs to be updated.

    You should use any of the above four methods, like:

    CCLabelTTF *label = [CCLabelTTF labelWithString@"a" fontname:@"Arial" fontsize:12 dimension:(CGSize)dimensions];
       label.verticalAlignment = ******
     or
       label.horizontalAlignment = ****
    

    This will call the constructor internally as mentioned above.