How to set background color in CCLabelTTF in cocos2d

烂漫一生 提交于 2019-12-12 11:09:46

问题


I am currently using Cocos2d FrameWork for my Game. I need to change the background color in a CCLabelTTF.I know how to set font color, can someone please tell me how to change background color of the CCLabelTTF object.

CCLabelTTF *nameLabel=[CCLabelTTF labelWithString:[NSString stringWithFormat:@"%@",[plyName objectAtIndex:i]] fontName:@"Arial" fontSize:20];
        nameLabel.position=ccp(100,y1);
        nameLabel.color=ccc3(245, 222, 179);
        [self addChild:nameLabel];

This is my sample code for adding Label. Any ideas?


回答1:


You can not set the background color of a CCLabelTTF.

What you can do is to display a single color CCSprite behind the label, or use CCLayerColor in the background with the same width and height of the label.



来源:https://stackoverflow.com/questions/7928968/how-to-set-background-color-in-cclabelttf-in-cocos2d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!