Search code examples
c++cocos2d-iphonecocos2d-x

Overlapping MenuItems in Cocos2d CCMenu


I am trying to make a Menu that contains 13 MenuItemImages in two columns (the last one is in the middle).

The frame width/ design resolution width is 480 pixels. MenuItemImage width is 180 pixels.

here is my code :
CCMenu* testMenu = CCMenu::createWithArray(testMenuItems);
testMenu->alignItemsInColumns(2,2,2,2,2,2,1);
CCSize size1 = CCDirector::sharedDirector()->getWinSize();
testMenu->setPosition(ccp(size1.width / 2, size1.height/2));

but the two columns are slightly overlapping. (the right one is above the left one) here is the result of my code:

enter image description here

I would like it to be properly spaced with some padding between the two columns. Please help me out I am new to Cocos2d-x.


Solution

  • the alignItemsInColumns will align menu itens based on itens center, against menu width.

    In your case, you have 2 options:

    1) Increase your menu width (by default, their size will be based on screen size. Change the menu.contentSize.width)

    2) Change the anchor point of left itens to ccp(.7,.5) and right itens to ccp(.3,.5) for example