1
我期望在屏幕左上角的「切換播放器」按鈕上方有一個「菜單」按鈕,但「菜單」按鈕的上半部分位於屏幕上方。怎麼來的?這是一個錯誤?將屏幕頂部的CCMenu對齊
左對齊是好的。
謝謝!
-(void) superSceneEnded
{
_sceneEnded = true;
CCMenu *menu = [CCMenu menuWithItems:nil];
menu.anchorPoint = ccp(0, 1); // Upper left corner
menu.position = ccp(2, _winSize.height - 2); // Almost at upp left corner of screen
[self addChild:menu];
[self addButton:menu :@"Menu" :@selector(goToMenu)];
if ([MatchMgr instance].currentMatch.isOnDevice)
{
[self addButton:menu :@"Switch player" :@selector(switchPlayer)];
}
[menu alignItemsVerticallyWithPadding:10];
}
-(void) addButton: (CCMenu*) menu: (NSString*) text: (SEL) selector
{
CCMenuItem *menuItem = [CCMenuItemImage itemFromNormalImage:@"button.png" selectedImage:@"button-pressed.png" target:self selector:selector];
menuItem.anchorPoint = ccp(0, 1); // Upper left corner
//menuItem.scale = 0.5;
[menu addChild:menuItem];
// The code below is not relevant for the question, but I keep it for your understanding.
CCLabelBMFont *bmText = [CCLabelBMFont labelWithString:text fntFile:@"MainFont.fnt"];
bmText.color = ccBLACK;
bmText.scale = 0.75;
bmText.alignment = NSTextAlignmentCenter;
bmText.position = ccp(75, 15);
[menuItem addChild: bmText];
}
不要更改CCMenu的anchorPoint,它完全與觸摸檢測和定位食堂。只設置位置。 – LearnCocos2D
好的,那麼我該如何在左上角放置一堆自動對齊的菜單按鈕?可能嗎? –