开发者

Cocos2D CCMenuItem over an other CCLayer doesn't respond

Here is m开发者_高级运维y problem. I got a classic CCLayer subclass. In the init method, I create a CCMenuItem, and add it to my main layer :

CCMenuItemFont *back = [CCMenuItemFont itemFromString:@"back" target:self selector:@selector(back)];
    [back setPosition:CGPointMake(30, 30)];
    [self addChild:back];

I don't understand why, the method 'back' is not called.

Thanks in advance


You need to add your menu items to a CCMenu, not directly to your layer.

CCMenuItemFont *back = [CCMenuItemFont itemFromString:@"back" target:self selector:@selector(back)];
[back setPosition:CGPointMake(30, 30)];

CCMenu *menu = [CCMenu menuWithItems:back,nil];
[menu setPosition:CGPointZero];
[self addChild:menu];

If that doesn't work, your back method may need to accept the parameter passed when the menu button is pressed, like this:

-(void) back:(CCMenuItem*) item;

If that's the case you'll need to add the parameter to the @selector call:

...selector:@selector(back:)];


try this.

CCMenuItemFont *back = [CCMenuItemFont itemFromString:@"back" target:self selector:@selector(back:)];

and change your back method to be..

-(void) back: (id) sender {
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜