cocos2d: Menu alignment in v0.6

cocos2d v0.6 introduces a manual way to align the items. You can align them both vertically and horizontally.
Prior to v0.6 the items were vertically aligned automatically. In v0.6 the automatic alignment feature was removed. If you want to align them you need to do this:

menu = [Menu menuWithItems:item1, item2, item3, nil];
[menu alignItemsHorizontally];

or:

menu = [Menu menuWithItems:item1, item2, item3, nil];
[menu alignItemsVertically];


Also, the previous vertical alignment algorithm had a bug, and wasn’t aligning the items in the center of the screen. If you want to use the old and buggy alignment algorithm you can do this:

menu = [Menu menuWithItems:item1, item2, item3, nil];
[menu alignItemsVerticallyOld];


The alignItemsVerticallyOld is deprecated and will be removed in v0.7.

Tip: you can place your MenuItem as well as the Menu manually like any other CocosNode:

menu = [Menu menuWithItems:item1, item2, item3, nil];
menu.position = cpv(0,0);
item1.position = cpv(50,50);
item2.position = cpv(200,200);

Working Example: MenuTest example. See MenuTest.m file.

0 Responses to “cocos2d: Menu alignment in v0.6”


  • No Comments

Leave a Reply