gpt4 book ai didi

iphone - 如何更改 Cocos2d MenuItem 的颜色?

转载 作者:太空狗 更新时间:2023-10-30 03:41:15 32 4
gpt4 key购买 nike

[MenuItemFont setFontSize:20];
[MenuItemFont setFontName:@"Helvetica"];
//I'm trying to change the color of start (below item)
MenuItem *start = [MenuItemFont itemFromString:@"Start Game"
target:self
selector:@selector(startGame:)];
MenuItem *help = [MenuItemFont itemFromString:@"Help"
target:self
selector:@selector(help:)];
Menu *startMenu = [Menu menuWithItems:start, help, nil];
[startMenu alignItemsVertically];
[self add:startMenu];

最佳答案

MenuItemFont *start =  [MenuItemFont itemFromString:@"Start Game" 
target:self
selector:@selector(startGame:)];

[start.label setRGB:0 :0 :0]; // Black menu item

Label 是 MenuItemFont 的一个属性,它是 MenuItem 的一个子类,因此在隐式转换为 MenuItem 时会丢失它。

或者,你可以这样做:

[((MenuItemFont *)start).label setRGB:0 :0 :0] 

(但这很丑陋,startMenu 将毫无怨言地采用 MenuItemFont)。

请记住,大部分颜色都硬编码在 MenuItemFont 中,因此调用“setIsEnabled”会将颜色设置回灰色或白色。如果您需要调整它,这会发生在 MenuItem.m 的第 239 行附近。如果我着手制作补丁以在 MenuItemFont 上公开此功能(假设它不在 .7.1 之前的源代码中),我将更新我的帖子。

关于iphone - 如何更改 Cocos2d MenuItem 的颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/558300/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com