views:

14

answers:

1

free4machine Member PM this user

Hi,

I want to make a sample animation:

there is a button at the bottom of the screen, a small menu will appear when this button is pressed. And there is an icon at the bottom of the small menu, the small menu will disappear when this icon is pressed.

The button, small menu, icon, all are instance of CCMenuItemImage .

Question: the small menu does not disappear when the icon is pressed. it seems that the icon does not respond for touch events.

Any suggestions or help will be appreciated

Sorry for my poor english.

here is the code:

CCMenuItemImage *bg = [CCMenuItemImage itemFromNormalImage:@"b1.png" selectedImage:@"b2.png" ];
CCMenuItemImage *button = [CCMenuItemImage itemFromNormalImage:@"button.png" selectedImage:@"button2.png" target:     self selector:@selector(showSideMenu:)];

CCMenuItemImage *sideMenu = [CCMenuItemImage itemFromNormalImage:@"s1.png" selectedImage:@"s2.png" ];
CCMenuItemImage *backbutton = [CCMenuItemImage itemFromNormalImage:@"backbutton.png" selectedImage:@"backbutton2.     png" target:self selector:@selector(hideSideMenu:)];

[ sideMenu addChild: backbutton ];

CCMenu *menu  =  [ CCMenu menuWithItems: bg,button, sideMenu, nil ];

[ self addChild: menu];

What did showSideMenu and hideSideMenu do is making sideMenu appear and disappear by using runAction.

thanks.

A: 

Based on the code, the only problem I see is that backButton isn't added as a child of the menu. Only bg, button, and sideMenu are in the list of arguments. By adding it as a child of bg, it won't trigger it's own selector, but bg's. And since bg doesn't have any defined, nothing happens. The simplest fix is to just add backbutton to the list. Your code will look like this:

CCMenuItemImage *bg = [CCMenuItemImage itemFromNormalImage:@"b1.png" selectedImage:@"b2.png" ];
CCMenuItemImage *button = [CCMenuItemImage itemFromNormalImage:@"button.png" selectedImage:@"button2.png" target:     self selector:@selector(showSideMenu:)];

CCMenuItemImage *sideMenu = [CCMenuItemImage itemFromNormalImage:@"s1.png" selectedImage:@"s2.png" ];
CCMenuItemImage *backbutton = [CCMenuItemImage itemFromNormalImage:@"backbutton.png" selectedImage:@"backbutton2.     png" target:self selector:@selector(hideSideMenu:)];

CCMenu *menu  =  [ CCMenu menuWithItems: bg,button, sideMenu, backbutton, nil ];

[ self addChild: menu];

If you want each of the buttons to be positioned relative to the menu, just set their position property.

jtalarico