【发布时间】:2011-07-29 16:18:31
【问题描述】:
我使用 Cocos2d iPhone 编写了一些游戏。在我之前的所有游戏中,我都会在设置 CCMenu 时更改场景,然后在完成后离开该场景。在我当前的项目中,我需要菜单存在于当前场景中,并且能够多次打开然后关闭菜单。出于某种原因,我似乎无法理解,removeChild 不会删除菜单。我在网上看到了几个使用 removeChild 的示例,但它对我不起作用。下面是我的菜单代码,当按下 Start/CreateNewAccount 按钮时,我希望将当前菜单完全从场景中删除。
这是在我的 init 方法中。
CCMenuItemImage *Start = [CCMenuItemImage itemFromNormalImage:@"MakeLemonade.png" selectedImage:@"MakeLemonadePressed.png"
target:self
selector:@selector(CreateNewAccount:)];
CCMenuItemImage *About = [CCMenuItemImage itemFromNormalImage:@"About.png" selectedImage:@"AboutPressed.png"
target:self
selector:@selector(About:)];
Start.position = ccp(-175, -90);
About.position = ccp(175, -90);
CCMenu *MainMenu = [CCMenu menuWithItems: Start, About, nil];
[Start runAction:[CCFadeIn actionWithDuration:1.0]];
[About runAction:[CCFadeIn actionWithDuration:1.0]];
[self addChild:MainMenu z:6];
}
return self;
}
-(void) BeginMenuLayer {
//this is not working
[self removeChild:MainMenu cleanup:YES];
}
【问题讨论】:
标签: iphone objective-c xcode cocos2d-iphone