如何从场景中的另一个图层中删除图层。 (Cocos2d)
我得到了这个场景的overviewScene,在这个场景中我添加了self作为图层,以及一个MainMenu图层。
概览层显示有关玩家的一些统计数据,菜单层显示在顶部。现在,当玩家单击菜单中的菜单点时,我想用另一层更改概述层。
但问题是,我似乎无法从 MainMenu 类中删除overviewscene 层,这可能吗?
:: 更新 ::
我相信这是我所尝试过的,让我打印一些代码。这是来自我的 MainMenuLayer
CCMenuItemFont menu_overview = [CCMenuItemFont itemFromString:@"Overview" target:self.parent selector:@selector(test)];
父级将是我的概览场景,因为该层已添加到我的该类中,对吗?
来自概览场景
-(void)test {
// CCScene *scene =[[CCDirector sharedDirector] runningScene];
// CCLayer *parentz = (CCLayer) self.parent;
//[[scene removeChild: cleanup:YES];
[[OverviewScene node] removeFromParentAndCleanup:YES];
}
I got this scene my overviewScene, in this scene i add self as layer, and a MainMenu layer.
The overview layer show some stats about the player, and the menu layer is displayed at the top. Now when the player clicks on a menu point in the menu, i want to change the overview layer out with another layer.
But the problem is, i can't seem to remove the overviewscene layer from the MainMenu class, is this even possible?
:: Update ::
i believe this i what i have tried, let me print some code. This is from my MainMenuLayer
CCMenuItemFont menu_overview = [CCMenuItemFont itemFromString:@"Overview" target:self.parent selector:@selector(test)];
The parent would be my overviewScene as this layer was added my that class right?
From overviewScene
-(void)test {
// CCScene *scene =[[CCDirector sharedDirector] runningScene];
// CCLayer *parentz = (CCLayer) self.parent;
//[[scene removeChild: cleanup:YES];
[[OverviewScene node] removeFromParentAndCleanup:YES];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
执行此操作的正确方法是拥有一个包含“概述”的父场景、要显示的新图层以及添加为子图层的“MainMenu”图层。通过这种方式,您可以简单地执行以下操作:
只要正确设置每个图层的 z 索引以维护层次结构,这将解决您的问题。
The correct way to do this would be to have a parent scene that has the "overview", the new layer you want to show and the "MainMenu" layers added as a child layers. This way you can simply do:
As long as you keep the z index of each layer set correctly to maintain hierarchy this will solve your problem.