我可以在两个 CCTMXLayer 之间放置一个 CCSprite 吗?

发布于 2024-12-04 04:09:24 字数 1147 浏览 3 评论 0原文

我正在制作一款自上而下的射击游戏,它广泛使用通过“Tiled”应用程序创建的 TMX 地图。在我的 TMX 地图中,我有一个带有地砖的“背景”图层,它出现在我的角色 (CCSprites) 下方。

在 TMX 文件中我还有另一个名为“前景”的图层,我希望它出现在我的 CCSprites 的“上方”,给出他们在各种物体下面行走的错觉。

我尝试使用 CCNode 类的 vertexZ 属性来执行此操作:

CCTMXLayer *backgroundLayer = ...
CCSprite *spriteNode = ...
CCTMXLayer *foregroundLayer = ...

[backgroundLayer setVertexZ:1];
[spriteNode setVertexZ:2];
[foregroundLayer setVertexZ:3];

...但事实证明 vertexZ 实际上改变了 openGL 视图中节点的视觉外观。当 CCNode 具有较高的 vertexZ 值时,它会有效地导致 CCNode 显得更大,或者更靠近用户。我不想要这样——我想要的只是一种不可思议的薄蛋糕层效果,各层之间没有任何视觉差异。

所以我想我应该尝试改变节点的 zOrder 属性,如下所示:

[[backgroundLayer parent] reOrderChild:backgroundLayer z:1];
[[spriteNode parent] reOrderChild:backgroundLayer z:2];
[[foregroundLayer parent] reOrderChild:backgroundLayer z:3];

但我意识到我在这里所做的有一个根本问题,因为我的 spriteNode 是 CCScene 的直接子节点,但背景和前景节点是我的 CCTMXTiledMap 的两个子级,CCTMXTiledMap 本身就是 CCScene 的子级。

因此,我基本上尝试在地图的两层之间滑动 CCSprite,从 CCScene 的角度来看,这实际上只是同一层的两个部分。

看来我可以创建一个额外的 CCTMXTiledMap 实例来保存前景层,但这似乎也有点矫枉过正。我的另一个想法是创建 CCSprites 来达到相同的目的,但似乎必须有更好的方法。

I am making a top-down shooter that makes extensive use of TMX maps created with the "Tiled" application. Within my TMX map, I have a "Background" layer with floor tiles, which appears beneath my characters (CCSprites.)

I have another layer in the TMX file called "Foreground" which I would like to appear "above" my CCSprites, giving the illusion of them walking underneath various objects.

I tried using the vertexZ property of the CCNode class to do this:

CCTMXLayer *backgroundLayer = ...
CCSprite *spriteNode = ...
CCTMXLayer *foregroundLayer = ...

[backgroundLayer setVertexZ:1];
[spriteNode setVertexZ:2];
[foregroundLayer setVertexZ:3];

...but it turns out vertexZ actually alters the node's visual appearance within the openGL view. It effectively causes a CCNode to appear larger, or closer to the user when it has a higher vertexZ value. I don't want that- all I want is a sort of layers-of-an-impossibly-thin-cake effect, without any visual differences between the layers.

So I thought I would try altering the zOrder property of the nodes, like this:

[[backgroundLayer parent] reOrderChild:backgroundLayer z:1];
[[spriteNode parent] reOrderChild:backgroundLayer z:2];
[[foregroundLayer parent] reOrderChild:backgroundLayer z:3];

But I realized there's a fundamental problem with what I'm doing here, since my spriteNode is a direct child of the CCScene, but the background and foreground nodes are both children of my CCTMXTiledMap, which itself is a child of the CCScene.

So I'm basically trying to slip a CCSprite between two layers of the map, which, from the CCScene's perspective, are really just two parts of the same layer.

It seems I could create an additional instance of CCTMXTiledMap just to hold the foreground layer, but that also seems like overkill. My other thought was to create CCSprites to serve the same purpose, but it seems like there's got to be a better way.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

雨落星ぅ辰 2024-12-11 04:09:24

是的,我曾经非常轻松地使用过 Tiled,并且我确实相信有一个选项可以将对象层添加到您的 TMXTiledMap 中(Tiled -> 图层 -> 添加对象层...),然后一旦导入到您的构建中,您就可以将 CCSprite 与您创建的相应对象层链接起来。我会在 cocos2d 论坛上发布你的问题,因为那里的人更有经验并且有能力用例子来回答这个问题。

Yes, I have used Tiled once very lightly and I do believe there is an option to add an Object Layer into your TMXTiledMap (Tiled -> Layer -> Add Object Layer...), then once imported into your build you can link up a CCSprite with the corresponding Object Layer you have created. I would post your question on the cocos2d forum, as people there are more experienced and equipped to answer this with examples.

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