如何从场景中的另一个图层中删除图层。 (Cocos2d)

发布于 2024-12-11 17:22:23 字数 697 浏览 0 评论 0原文

我得到了这个场景的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

z祗昰~ 2024-12-18 17:22:23

执行此操作的正确方法是拥有一个包含“概述”的父场景、要显示的新图层以及添加为子图层的“MainMenu”图层。通过这种方式,您可以简单地执行以下操作:

[self removeChild:overviewLayer]; // overviewLayer is a reference to overview layer
[self addChild:otherLayer tag:kYourTag z:yourZValue]; // otherLayer is the new layer you want added, mind the z index

只要正确设置每个图层的 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:

[self removeChild:overviewLayer]; // overviewLayer is a reference to overview layer
[self addChild:otherLayer tag:kYourTag z:yourZValue]; // otherLayer is the new layer you want added, mind the z index

As long as you keep the z index of each layer set correctly to maintain hierarchy this will solve your problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文