情况:
使用 cocos2d 的 CCMenuItem 和 CCMenu 类,我按以下方式创建菜单。
问题:
菜单项居中对齐。我希望它们左对齐(意思是说每个项目的第一个字母的 x 坐标大致相同)
问题:
如何左对齐 CCMenuItems? *如果您能告诉我如何将多个 CCLabelTTF 项目也左对齐到给定的 x 坐标,加分。
CCMenuItemFont *newGame = [CCMenuItemFont itemFromString:@"New Game" target:self selector:@selector(onNew:)];
CCMenuItemFont *loadGame = [CCMenuItemFont itemFromString:@"Load Game" target:self selector:@selector(onLoad:)];
CCMenuItemFont *options = [CCMenuItemFont itemFromString:@"Options" target:self selector:@selector(onOptions:)];
CCMenu *menu = [CCMenu menuWithItems: newGame, loadGame, options, nil];
menu.position = ccp(160.0, 220.0);
[menu alignItemsVerticallyWithPadding: 28.0];
[self addChild:menu z:1];
最佳答案
你可以尝试手动设置坐标
比如 iPad:
newgame.position = ccp(200,150);
loadgame.position = ccp(200,0);
options.position = ccp(200,-150);
[newgame setAnchorPoint:ccp(2,2)];
[loadgame setAnchorPoint:ccp(2,2)];
[options setAnchorPoint:ccp(2,2)];
关于iphone - 如何左对齐 CCMenuItems?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9546808/