2014-09-02 163 views
1

我使用下面的代码自定义字体

MenuItemFont* supportMenuItem = MenuItemFont::create("Contact us for support", 
                  CC_CALLBACK_1(TempLogoLayer::supportMenuClicked, this)); 


supportMenuItem->setPosition(Vec2(100,100)); 
supportMenuItem->setFontName("Arial"); 
supportMenuItem->setFontSize(16.0); 


Menu *buttonsMenu = CCMenu::create(supportMenuItem, NULL); 
buttonsMenu->setPosition(Vec2(0.0, 0.0)); 
this->addChild(buttonsMenu, 1) 

创建菜单项,但该菜单项没有采取字体

回答

1

你可以这样做:

item = MenuItemFont::create("item 1"); 
item->retain(); 

auto back = MenuItemFont::create("go back", CC_CALLBACK_1(RemoveMenuItemWhenMove::goBack, this)); 

这是cocos2d的-X 3.2你可以检查示例目录MenuTest.cpp并查看它是如何工作的。

0

我意识到这是真的老了,但其他人可能很可能在某个时候在这个岗位绊倒: 对于Cocos2dx 3.6尝试:

supportMenuItem->setFontNameObj("Arial");

还要确保字体叫做“宋体“是在字体目录

这实际上会做伎俩。 OP很接近。

1

Arial字体,您可以使用标签来代替

auto lbRate = Label::createWithSystemFont("4 Rate", "Arial", 35.0); 
auto menuRate = MenuItemLabel::create(lbRate, CC_CALLBACK_1(PlayerSkin::onRate, this)); 
auto menu = Menu::create(menuRate, NULL); 
this->addChild(menu, 10);