将CCMenu对齐到网格 [英] Aligning CCMenu to a grid
本文介绍了将CCMenu对齐到网格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有人知道最佳实践方法获得一个CCMenuItems数组对齐网格?这是一个cocos2d问题
Does anybody know the best practice approach to getting an array of CCMenuItems to align to a grid? This is a cocos2d question
例如:
int levelCount = 10;
CCMenu *menuArray = [CCMenu menuWithItems:nil];
for (int x = 1; x<=levelCount; x++) {
CCLOG(@"Creating level icon for Level %i", x);
[menuArray addChild:[CCMenuItemImage itemFromNormalImage:@"Button2n.png"
selectedImage:@"Button2s.png"
target:self
selector:@selector(onPlay:)]];
}
[menuArray alignToGridWouldbeGreat????!!!!];
[self addChild:menuArray];
我可以在列或行中垂直,水平排列,但不能包括列或行配置。
I can align vertically, horizontally, in columns or rows however cannot wrap a column or row configuration.
提前感谢!
推荐答案
的重载的alignItemsInColumns或alignItemsInRows方法。例如,如果您有15个菜单项,并且您想要3行5列,请执行以下操作:
You just have to call one of the overloaded alignItemsInColumns or alignItemsInRows methods. For example if you have 15 menu items and you want 3 rows of 5 columns, do this:
CCMenu* menu = [CCMenu menuWithItems:...];
NSNumber* itemsPerRow = [NSNumber numberWithInt:5];
[menu alignItemsInColumns:itemsPerRow, itemsPerRow, itemsPerRow, nil];
唯一的缺点是,似乎没有办法设置填充,一个网格。
The only down side is that there doesn't seem to be a way to set padding when aligning to a grid.
这篇关于将CCMenu对齐到网格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文