Cocos study notes-Menu

来源:互联网 发布:java中字符串转json 编辑:程序博客网 时间:2024/06/08 19:52

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 typefacestatic void setFontSize(int size);static int getFontSize();//the name of typefacestatic 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 disabledSpriteinline 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 MenuItemstatic MenuItemToggle *createWithCallback(const MenuCallback& callback,const Vector<MenuItem*>&menuItem);//create with plenty of MenuItemstatic MenuItemToggle* createWithCallback(const MenuCallback& callback,MenuItem* item,...,NULL);//create an empty MenuItemTogglestatic MenuItemToggle* create();//add MenuItem to itvoid addSubItem(MenuItem *item);MenuItem* getSelectedItem();
0 0
原创粉丝点击