2011-11-30 48 views
1

我在我的遊戲中移動了精靈,並在其上添加了標籤(CCLabelTTF)。標籤有A,B,C等字符。我想對標籤的內容給予陰影效果,以便它們可以正常顯示。如何給cocos2D中的標籤項目添加陰影效果?

in .h file我有

CCLabelTTF * label;

在.m中我已設置其位置和顏色。 「目標」是有標籤的精靈。

target=[CCSprite spriteWithFile:[NSString stringWithFormat:@"balloon%d.png",enType] rect:CGRectMake(0, 0, 100, 119)]; 

label = [[CCLabelTTF alloc] initWithString:alphabetValue dimensions:CGSizeMake([target contentSize].width, [target contentSize].height) 
            alignment:UITextAlignmentCenter fontName:@"verdana" fontSize:30.0f]; 

    //LABEL POSITION HERE 
    label.position = ccp(55,30); 

    label.color = ccc3(60,60,60); 

    [target addChild:label z: 10]; 

現在我想給一個陰影效果......我該怎麼辦呢?

回答

6

添加相同的標籤兩次,一次稍大。應首先創建陰影標籤,使其出現在實際標籤的後面,或使用z屬性。

CGSize size = CGSizeMake([target contentSize].width, [target contentSize].height); 
labelShadow = [[CCLabelTTF alloc] initWithString:alphabetValue 
           dimensions:size 
           alignment:UITextAlignmentCenter 
            fontName:@"verdana" fontSize:30.0f]; 
labelShadow.position = ccp(55+2,30+2); // slightly offset 
labelShadow.color = ccc3(10,10,10); 
[target addChild:labelShadow z:10]; 

label = [[CCLabelTTF alloc] initWithString:alphabetValue 
           dimensions:size 
           alignment:UITextAlignmentCenter 
            fontName:@"verdana" fontSize:30.0f]; 
label.position = ccp(55,30); 
label.color = ccc3(60,60,60); 
[target addChild:label z:10]; 

您還可以嘗試稍微縮放labelShadow,或增加其fontSize。

注意:它不會創建柔和(模糊)的陰影。爲此,您可以使用texture filter methods available here