I have CCMenu
with 5 CCMenuItem
s. When a user touches a menu item, I want the menu item to move 10 pixels to the right to distinguish it from others. I tried to make each menu item a global variable so that I could say: if (item.isSelected) { [item runAction:blah]; }
if (item.isSelected) { [item runAction:blah]; }
But it did nothing. This is my code:
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)]]; }
My question is: how can I achieve the effect that I mentioned earlier? I want the selected CCMenuItem
move 10 pixels to the right when the user touches it, but does not release it, and then returns to its normal position when the touch item leaves this menu item. Also, where should I put this animation code? In my init
function? thanks for the help
source share