CCMenuItemFont can not change color, always white

407 Views Asked by At

I tried below two methods to change the color of CCMenuItemFont,but does not work. It's always white.

CCMenuItemFont *gameItem=[CCMenuItemFont itemWithString:@"Game" target:self selector:@selector(goToPlay:)];
[gameItem setColor:ccGRAY];

or

gameItem.color=ccGRAY;

what's the problem?

2

There are 2 best solutions below

0
On

CCMenuItemFont is a subclass of CCMenuItemLabel. We should actually set the color of the CCLabelTTF which is added as a child on CCMenuItemFont or CCMenuItemLabel. We can actually change item color like this

CCMenuItemFont *gameItem=[CCMenuItemFont itemWithString:@"Game" target:self selector:@selector(goToPlay:)];
////[gameItem setColor:ccGRAY];     //No effect.
gameItem.label.color = ccGRAY;      //Eureka. Color changed
2
On

Try changing to a CCMenuItemLabel:

CCMenuItemLabel *gameItem = [CCMenuItemFont itemWithString:@"Play" 
                     target:self selector:@selector(goToPlay:)];
gameItem.color=ccGRAY;