画布层

Godot Canvas layers(画布层)

Viewport and Canvas items

Regular 2D nodes, such as Node2D or Control both inherit from CanvasItem, which is the base for all 2D nodes. CanvasItems can be arranged in trees. Each item will inherit its parent’s transform. This means that when the parent is moved, the children will move too.
常规的2D节点,如Node2D或Control都继承自CanvasItem,它是所有2D节点的基础。CanvasItems可以以树状排列。每个项目将继承其父节点的变换。这意味着当父节点被移动时,子节点也会移动。

CanvasItem nodes, and nodes inheriting from them, are direct or indirect children of a Viewport, and will be displayed through it.
CanvasItem节点,以及从CanvasItem节点继承的节点,都是Viewport的直接或间接子节点,并将通过它来显示。

A Viewport has the property Viewport.canvas_transform, which allows applying a custom Transform2D transform to the CanvasItem hierarchy it contains. Nodes such as Camera2D work by changing that transform.
一个Viewport具有Viewport.canvas_transform属性,它允许对它所包含的CanvasItem层次结构应用一个自定义的Transform2D变换。像Camera2D这样的节点通过改变该变换来工作。
在这里插入图片描述

Effects like scrolling are best achieved by manipulating the canvas transform property. This approach is more efficient than moving the root canvas item (and hence the whole scene).
滚动等效果最好通过操作 canvas transform属性来实现。这种方法比移动根画布项(从而移动整个场景)更有效。

Usually though, we don’t want everything in the game or app to be subject to the canvas transform. Examples of this are:
不过通常情况下,我们并不希望游戏或应用中的所有内容都受画布的变换影响。这方面的例子有:

Parallax Backgrounds: Backgrounds that move slower than the rest of the stage.
视差背景:背景的移动速度比舞台的其他部分慢。
UI: Think of a user interface (UI) or Heads-up display (HUD) superimposed on our view of the game world. We want a life counter, score display and other elements to retain their screen positions even when our view of the game world is changing.
UI:想象一个UI(用户界面)或HUD(平视显示器) 叠加在我们的游戏世界视图上。我们想要生命计数器,分数显示等东西保持其屏幕位置,即使当游戏世界中的视角正在改变时他们也不动。
Transitions: We may want visual effects used for transitions (fades, blends) to remain at a fixed screen location.
转场:我们可能希望用于过渡的视觉效果(淡入淡出、混合)保持在一个固定的屏幕位置。

How can these problems be solved in a single scene tree?
如何在一个场景树中解决这些问题呢?

CanvasLayers

The answer is CanvasLayer, which is a node that adds a separate 2D rendering layer for all its children and grand-children. Viewport children will draw by default at layer “0”, while a CanvasLayer will draw at any numeric layer. Layers with a greater number will be drawn above those with a smaller number. CanvasLayers also have their own transform and do not depend on the transform of other layers. This allows the UI to be fixed in screen-space while our view on the game world changes.
答案是CanvasLayer,它是一个节点,为它的所有子级和孙级添加一个单独的2D渲染层。Viewport的子级默认会在 "0 "层绘制,而CanvasLayer则会在任何数字层绘制。数字较大的图层将绘制在数字较小的图层之上。CanvasLayers也有自己的变换,不依赖于其他层的变换。这使得当我们游戏世界的视图发生变化时,UI可以固定在屏幕空间中。

An example of this is creating a parallax background. This can be done with a CanvasLayer at layer “-1”. The screen with the points, life counter and pause button can also be created at layer “1”.
一个例子是创建一个视差背景。这可以通过在图层"-1 "处创建CanvasLayer来完成。也可以在图层 "1 "处创建带有分数、生命计数器和暂停按钮的画面。

Here’s a diagram of how it looks:
下面是它的图示:
../../_images/canvaslayers.png

CanvasLayers are independent of tree order, and they only depend on their layer number, so they can be instantiated when needed.
CanvasLayers与树的顺序无关,它们只取决于它们的层号,因此可以在需要时实例化。

Note
CanvasLayers aren’t necessary to control the drawing order of nodes. The standard way to ensuring that a node is correctly drawn ‘in front’ or ‘behind’ others is to manipulate the order of the nodes in the scene panel. Perhaps counterintuitively, the topmost nodes in the scene panel are drawn on behind lower ones in the viewport. 2d nodes also have a property for controlling their drawing order (see Node2D.z_index).
CanvasLayers不需要控制节点的绘制顺序。确保一个节点正确地画在其他节点的 "前面 "或 "后面 "的标准方法是操纵场景面板中节点的顺序。也许与直觉相反,场景面板中最上面的节点在视口中被画在较低节点的后面。二维节点也有一个属性来控制它们的绘制顺序(见Node2D.z_index)。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
提供的源码资源涵盖了安卓应用、小程序、Python应用和Java应用等多个领域,每个领域都包含了丰富的实例和项目。这些源码都是基于各自平台的最新技术和标准编写,确保了在对应环境下能够无缝运行。同时,源码中配备了详细的注释和文档,帮助用户快速理解代码结构和实现逻辑。 适用人群: 这些源码资源特别适合大学生群体。无论你是计算机相关专业的学生,还是对其他领域编程感兴趣的学生,这些资源都能为你提供宝贵的学习和实践机会。通过学习和运行这些源码,你可以掌握各平台开发的基础知识,提升编程能力和项目实战经验。 使用场景及目标: 在学习阶段,你可以利用这些源码资源进行课程实践、课外项目或毕业设计。通过分析和运行源码,你将深入了解各平台开发的技术细节和最佳实践,逐步培养起自己的项目开发和问题解决能力。此外,在求职或创业过程中,具备跨平台开发能力的大学生将更具竞争力。 其他说明: 为了确保源码资源的可运行性和易用性,特别注意了以下几点:首先,每份源码都提供了详细的运行环境和依赖说明,确保用户能够轻松搭建起开发环境;其次,源码中的注释和文档都非常完善,方便用户快速上手和理解代码;最后,我会定期更新这些源码资源,以适应各平台技术的最新发展和市场需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值