2014-09-02 137 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);