CCMenuItemImage按钮不起作用

时间:2011-12-30 11:12:34

标签: cocos2d-iphone

按钮和菜单在屏幕上,但按下按钮时没有任何反应:

CCMenuItemImage *menuB = [CCMenuItemImage itemFromNormalImage:@"menuB.png" selectedImage:@"menuB.png" target:self selector:@selector(goMenu:)];
    CCMenuItemImage *tryAgainB = [CCMenuItemImage itemFromNormalImage:@"tryAgainB.png" selectedImage:@"tryAgainB.png" target:self selector:@selector(tryAgain:)];
    CCMenuItemImage *menuGoodByeT = [CCMenuItemImage itemFromNormalImage:@"menu.png" selectedImage:@"menu.png" target:self selector:@selector(nothing:)];

    menuB.position=ccp(-65,-40);
    tryAgainB.position=ccp(15,-40);


    menu = [CCMenu menuWithItems:menuGoodByeT,menuB,tryAgainB, nil];
     menu.isTouchEnabled = YES;     
    [self addChild: menu];

是的,该方法具有:id sender

这个菜单怎么了?它总是有问题。

2 个答案:

答案 0 :(得分:3)

好吧,我想我明白了 - >

你在哪里坚持这段代码?

<{1>}中的

???如果是,请检查您是否致电-(void)onEnter{。否则,你会遇到很多问题

其次,如果那不起作用,那么检查一下是否有其他任何接触,因为你的菜单可能在另一层后面

答案 1 :(得分:0)

我尝试使用你的代码它完美无缺.....我工作如下,你可以参考代码.....我已经将图像名称更改为我拥有的图标和单一选择器方法它工作用这三种方法。

-(id) init 
{
    if((self = [super init])) 
    {
        CGSize winSize = [CCDirector sharedDirector].winSize;
        self.isTouchEnabled = YES;
        CCMenuItemImage *menuB = [CCMenuItemImage itemFromNormalImage:@"Icon-72.png" selectedImage:@"Icon-72.png" target:self selector:@selector(goMenu:)]; // Changed the Images and Selector Method
        CCMenuItemImage *tryAgainB = [CCMenuItemImage itemFromNormalImage:@"Icon-72.png" selectedImage:@"Icon-72.png" target:self selector:@selector(goMenu:)];
        CCMenuItemImage *menuGoodByeT = [CCMenuItemImage itemFromNormalImage:@"Icon-72.png" selectedImage:@"Icon-72.png" target:self selector:@selector(goMenu:)];

         menuB.position=ccp(-65,-40);
         tryAgainB.position=ccp(15,-40);        
         CCMenu * menu = [CCMenu menuWithItems:menuGoodByeT,menuB,tryAgainB, nil];
         menu.isTouchEnabled = YES;     
         [self addChild: menu];
    }
return self;
}


-(void) goMenu:(id) sender
 {
     NSLog(@"Go menu pressed");
 }