how to Expand CCMeunItem to display both image and text?

how to Expand CCMeunItem to display both image and text?
0.0 0


i want to show Complex menu,all menuitem of menu is Composition by image and text。how to do this?


You can simply add some Label and sprite to CCMenuItems childs:

CCSprite* sprite = CCSprite::create();
CCLabelTTF* label = CCLabel::create();
CCMenuItem* item = CCMenuItem::create();


Or you can derive your own class from the CCMenuItem and save all you want in member variables.


This was pretty helpful for me too. Thanks. I expanded on it.


Would you have any input on how to layout a CCMenu in a grid format? So take the MenuItems and say make 2 rows, 3 in each row?


It is CCTableView in Extensions of cocos2dx, with formatting that you need. But putting on it CCMenu buttons may cause some problems with touches, like :

because CCTableView is derived from CCScrollView.

You can also make a grid format by yourself, create some derived class from CCNode, declare something like a rowCount, colCount, currentRow, currentCol, and overload addChield method, so you can set offsets and verify max count of elements in row and col.


Helpful, thank you!