cocos study notes-Menu
reference: jellythink
In cocos-2d-x, its menu UI system can be divided to three catageries:
- MenuItemLabel
- MenuItemSprite
- MenuItemToggle
Now, let’t talk about them in detail.
1.MenuItemLabel
It is a MenuItem
which was defined by typeface, or we can say this is a MenuItem
which can be used to write words on it. MenuItemLabel
includes MenuItemAtlasFont
and MenuItemFont
.
MenuItemFont
is a class which can set the size and name of typeface. This is its member functions:
static MenuItemFont *create(const std::string& value="start");
static MenuItemFont *create(const std::string& value,const MenuCallback& callback);
//the size of typeface
static void setFontSize(int size);
static int getFontSize();
//the name of typeface
static void setFontName(const std::string& name);
static const std::string& getFontName();
MenuItemAlasFont
is created by typeface file,something alike plist file.
2.MenuItemSprite
MenuItemSprite
is a class which can load picture.First, let’s see its member functions:
static MenuItemSprite *create(Node* normalSprite,Node* selectedSprite,Node* disabledSprite=nullptr);
static MenuSprite *create(Node* normalSprite,Node* selectSprite,Node* disabledSprite,const MenuCallback* callback); //sometimes we can omit the disabledSprite
inline Node* getNormalImage()cosnt {return _normalImage;};
void setNormalImage(Node* image);
//the other two can be inferred by the functions above.
3.MenuItemToggle
You can pass any MenuItem
to the MenuItemToggle
,which can be treated as a button.And its member function:
//create with a vector containing MenuItem
static MenuItemToggle *createWithCallback(const MenuCallback& callback,const Vector<MenuItem*>&menuItem);
//create with plenty of MenuItem
static MenuItemToggle* createWithCallback(const MenuCallback& callback,MenuItem* item,...,NULL);
//create an empty MenuItemToggle
static MenuItemToggle* create();
//add MenuItem to it
void addSubItem(MenuItem *item);
MenuItem* getSelectedItem();