Cocos2d个人按钮放置

时间:2014-06-21 19:28:30

标签: ios cocos2d-iphone

我支付了一名自由职业者为我制作游戏。我在正常的Ojct-C和故事板方面经验丰富但不是coco2sd。他为游戏结束时制作了一个菜单。 3个按钮(社交媒体共享按钮)和1个重播按钮。我正在尝试向上移动社交媒体按钮(为iads腾出空间),但将重播按钮保持在同一个位置。代码如下:

-(void)createMenu
{
btnNextpeer=newButtonPosA(@"next", POS_BTN_NEXT, self, @selector(onNextpeerClicked:), true, RATIO_Y, F_BTN_SCALE);
btnEM=newButtonPosA(@"em", POS_BTN_EM, self, @selector(onClickEM:), false, RATIO_Y, F_BTN_SCALE);
btnFB=newButtonPosA(@"fb", POS_BTN_FB, self, @selector(onClickFB:), false, RATIO_Y, F_BTN_SCALE);
btnTW=newButtonPosA(@"tw", POS_BTN_TW, self, @selector(onClickTW:),false, RATIO_Y, F_BTN_SCALE);
btnGC=newButtonPosA(@"gc", POS_BTN_GC, self, @selector(onClickGC:), true, RATIO_Y, F_BTN_SCALE);
btnRestart=newButtonPosA(@"restart", POS_BTN_RESTART, self, @selector(onClickRestart:), false, RATIO_Y, 1.0);

menu=[CCMenu menuWithItems:btnNextpeer,btnEM,btnFB,btnTW,btnGC,btnRestart, nil];
[menu setPosition:ccp(0,30)];
[self addChild:menu z:Z_BTN];
[self showButtons:false];
}

(0,0)是默认位置。我希望社交媒体按钮位于(0,30)但重播位于(0,0)。

这是我试图将重播按钮移动到(0,0):

menu=[CCMenu menuWithItems:btnNextpeer,btnEM,btnFB,btnTW,btnGC,btnRestart, nil];
[btnRestart setPosition:ccp(0, 100)];
[menu setPosition:ccp(0,30)];
[self addChild:menu z:Z_BTN];
[self showButtons:false];

当我添加简单的代码行时,重播按钮消失了。 任何帮助将不胜感激,谢谢!

2 个答案:

答案 0 :(得分:0)

您无法(自由)重新定位菜单中的各个项目。而是将每个项目放在自己的菜单中,然后您可以通过更改菜单的位置(而不是菜单项目)单独定位每个菜单。

答案 1 :(得分:0)

这是一个游戏的例子。 GETextMenuItem是我的生物之一,基本上它扩展了CCMenuItemLabel并添加了长触摸(显示工具提示),标签和工具提示的预先设置的字体和字体大小,以及一些在触摸过程中略微超大的行为。但这是:

CGSize dims = CGSizeMake(deviceOffset(230), deviceOffset(40));

// a bunch of other menu items before 

GETextMenuItem *fx = [GETextMenuItem textMenuItemWithText:@"FX volume"
                                               dimensions:dims
                                                alignment:kCCTextAlignmentLeft
                                                     font:kMPAmenuFont
                                                 fontSize:deviceFontSize(16)
                                                    color:ccWHITE
                                                   target:nil selector:nil];
fx.toolTip = @"Adjusts the sound effects volume from mute to the current master volume.";

GETextMenuItem *music = [GETextMenuItem textMenuItemWithText:@"Music volume"
                                                  dimensions:dims
                                                   alignment:kCCTextAlignmentLeft
                                                        font:kMPAmenuFont
                                                    fontSize:deviceFontSize(16)
                                                       color:ccWHITE
                                                      target:nil selector:nil];
music.toolTip = @"Adjusts the music setting volume from mute to the current master volume.";

CCMenu *labelMenu = [CCMenu menuWithItems:showDialogs, showHelp, showConfirmation, master, fx, music, nil];

float hOffs = -kScreenWidth / 2 + dims.width / 2 + _leftMargin;

showDialogs.position      = ccp(hOffs, kScreenHeight / 2 - _topMargin);
showHelp.position         = ccp(hOffs, kScreenHeight / 2 - _topMargin - 1 * _toggleMenuSpacing);
showConfirmation.position = ccp(hOffs, kScreenHeight / 2 - _topMargin - 2 * _toggleMenuSpacing);
master.position           = ccp(hOffs, kScreenHeight / 2 - _topMargin - 3 * _toggleMenuSpacing);
fx.position               = ccp(hOffs, kScreenHeight / 2 - _topMargin - 4 * _toggleMenuSpacing);
music.position            = ccp(hOffs, kScreenHeight / 2 - _topMargin - 5 * _toggleMenuSpacing);

labelMenu.position = ccp(0, 0);
[self addChild:labelMenu];

所以,我放置菜单屏幕,并将每个按钮放在屏幕左侧的_leftMargin,并从顶部放下_topMargin。对于这个'菜单'我不使用任何目标,这样做的唯一一点就是在按下标签时获取工具提示(帮助文本)。这就是它的结果:

enter image description here

相关问题