Actionscript 3:使子 A 中的某些对象出现在子 B 上方,而其他对象出现在子 B 下方

发布于 2024-08-04 03:25:52 字数 272 浏览 2 评论 0原文

想象我有一个背景,我想在玩家对象下显示背景。这可以轻松完成:

var player:Player = new Player();
addChild(player);

var background:Background = new Background();
addChildAt(background, 0);

但是,想象一下在这个背景中,我有透明的云,必须出现在船的上方,不透明的星星需要出现在船的下方。上面的代码只会让所有背景对象都进入船下。有什么建议吗?

Imagine I have a background and I want to show the background under the player object. This can be done with ease:

var player:Player = new Player();
addChild(player);

var background:Background = new Background();
addChildAt(background, 0);

However, imagine in this background I have transparent clouds which have to appear above the ship and non-transparent stars which need to appear under the ship. The above code would simply make all background objects go under the ship. Any tips?

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

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

发布评论

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

评论(1

腹黑女流氓 2024-08-11 03:25:52

创建一个在 Player 对象之后渲染的前景层。这是实现这种效果的最简单方法。

var foreground:* = ...;
addChildAt(foreground, 2);

我想象您将在前景层和背景层之间出现多个对象,因此我实际上还建议创建一个“活动”层,它是“玩家”对象的实际父级。

所以对象层次结构看起来类似于:

Scene
    Background
        Rolling hills
    Active
        Player Sprite
        Enemies
        Obstacles
    Foreground
        Clouds

Make a foreground layer that is rendered after the Player object. That is the easiest way to accomplish this effect.

i.e.

var foreground:* = ...;
addChildAt(foreground, 2);

I'd imagine you're going to have multiple objects that you want to appear between the foreground and background layers, so I would actually also recommend creating an "active" layer, which is the actual parent of your "player" object.

So the object hierarchy looks akin to this:

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