将 CCMenu 与网格对齐

Aligning CCMenu to a grid(将 CCMenu 与网格对齐)
本文介绍了将 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 与网格对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to stop UIBarButtonItem text from truncating?(如何阻止UIBarButtonItem文本被截断?)
java.lang.IllegalStateException: SimpleTypeImpl should not be created for error type(异常:不应为错误类型创建SimpleTypeImpl)
Android IllegalArgumentException: The tag for fragment_XXX is invalid. Received: layout-sw600dp/fragment_XXX_0(Android IlLegalArgumentException:Fragment_XXX的标签无效。收到:Layout-sw600dp/Fragment_XXX_0)
NSURLSessionTaskPriority seems to be ignored?(NSURLSessionTaskPriority似乎被忽略了?)
How to make dataWithEPSInsideRect vector rather than bitmap in vector format?(如何用EPSInside Rect将dataWithEPSInside Rect变成矢量而不是位图的矢量格式?)
HTTPS request using volley(使用 volley 的 HTTPS 请求)