我有一个CCMenu
5CCMenuItem
秒。当用户触摸菜单项时,我希望菜单项向右移动 10 个像素,以与其他菜单项区分开来。我尝试将每个菜单项设为全局变量,这样我就可以说:if (item.isSelected) { [item runAction:blah]; }
但这并没有做任何事情。到目前为止,这是我的代码:
CCLabelTTF *sin = [CCLabelTTF labelWithString:@"Single Player" dimensions:labelSize alignment:UITextAlignmentLeft fontName:font fontSize:20];
item1 = [CCMenuItemLabel itemWithLabel:sin target:self selector:@selector(goToSinglePlayer:)];
CCLabelTTF *spl = [CCLabelTTF labelWithString:@"Splitscreen" dimensions:labelSize alignment:UITextAlignmentLeft fontName:font fontSize:20];
item2 = [CCMenuItemLabel itemWithLabel:spl target:self selector:@selector(goToSplitscreen:)];
CCLabelTTF *ach = [CCLabelTTF labelWithString:@"Achievements" dimensions:labelSize alignment:UITextAlignmentLeft fontName:font fontSize:20];
item3 = [CCMenuItemLabel itemWithLabel:ach target:self selector:@selector(goToAchievements:)];
CCLabelTTF *str = [CCLabelTTF labelWithString:@"Store" dimensions:labelSize alignment:UITextAlignmentLeft fontName:font fontSize:20];
item4 = [CCMenuItemLabel itemWithLabel:str target:self selector:@selector(goToStore:)];
CCLabelTTF *set = [CCLabelTTF labelWithString:@"Settings" dimensions:labelSize alignment:UITextAlignmentLeft fontName:font fontSize:20];
item5 = [CCMenuItemLabel itemWithLabel:set target:self selector:@selector(goToSettings:)];
CCMenu * mainMenu = [CCMenu menuWithItems:item1, item2, item3, item4, item5, nil];
[mainMenu setColor:ccBLACK];
[mainMenu alignItemsVerticallyWithPadding:10];
mainMenu.position = ccp(90, 90);
[self addChild:mainMenu];
if (item1.isSelected) {
[item1 runAction:[CCMoveTo actionWithDuration:1.0f position:ccp(120, 90)]];
}
我的问题是:如何才能达到我前面提到的效果?当用户触摸它但不释放时,我希望所选CCMenuItem
对象向右移动 10 个像素,然后在触摸离开该菜单项时返回其正常位置。另外,我应该把这个动画代码放在哪里?在我的init
功能中?谢谢您的帮助