以下是我最终解决的方法:基本上我首先创建了菜单元素,然后我整理了定位/缩放/旋转。这似乎工作得更好。下面的代码示例是我使用单个精灵创建两个相对的左/右箭头按钮的地方
[[CCSpriteFrameCache sharedSpriteFrameCache] addSpriteFramesWithFile:@"ButtonSprites.plist"];
CCSpriteBatchNode *buttonSprites = [CCSpriteBatchNode batchNodeWithFile:@"ButtonSprites.png"];
[self addChild:buttonSprites];
CCSprite *arrowLeftSprite = [CCSprite spriteWithSpriteFrameNameOrFile:@"PageArrow"];
CCSprite *arrowLeftSpriteSelected = [CCSprite spriteWithSpriteFrameNameOrFile:@"PageArrow"];
arrowLeftSpriteSelected.opacity = 128;
CCSprite *arrowRightSprite = [CCSprite spriteWithSpriteFrameNameOrFile:@"PageArrow"];
CCSprite *arrowRightSpriteSelected = [CCSprite spriteWithSpriteFrameNameOrFile:@"PageArrow"];
arrowRightSpriteSelected.opacity = 128;
float buttonWidth = screenSize.width * ButtonWidthPercent;
int contentPixelWidth = arrowLeftSprite.contentSize.width;
float scale = buttonWidth / contentPixelWidth;
CCMenuItemSprite *pageLeftMenu = [CCMenuItemSprite itemFromNormalSprite:arrowLeftSprite selectedSprite:arrowLeftSpriteSelected target:self selector:@selector(buttonPageLeft:)];
CCMenuItemSprite *pageRightMenu = [CCMenuItemSprite itemFromNormalSprite:arrowRightSprite selectedSprite:arrowRightSpriteSelected target:self selector:@selector(buttonPageRight:)];
// First perform the creation
CCMenu *menu = [CCMenu menuWithItems: mainMenu, pageLeftMenu, pageRightMenu, nil];
menu.position = ccp(0, 0);
// THEN deal with layout,rotation, and scaling
pageLeftMenu.scale = scale;
pageLeftMenu.rotation = 180;
pageRightMenu.scale = scale;
float arrowHeight = screenSize.height * 0.2;
pageLeftMenu.position = ccp(screenSize.width * 0.1, arrowHeight);
pageRightMenu.position = ccp(screenSize.width * 0.9, arrowHeight);
[self addChild:menu z:2];