我正在研究Godot Engine和GDScript,并且我在互联网上搜索了有关键盘事件的信息,但我听不懂。Godot中是否有类似的东西on_key_down("keycode")?
我正在研究 Godot 引擎,我想知道为什么场景中不能有多个节点或元素。戈多不允许我这样做。为什么?
假设我正在使用 gdscript 静态类型,并且对于一个函数参数,我事先不知道我会得到什么。这就是typing.Anypython 中的用途。我该如何使用 gdscript 来做到这一点?
这似乎Variant不是一个有效的类型,我不确定是否用于Object该目的(因为它可能是内置的)
编辑 将类型留空显然是可行的,但是文档有一个名为typed-or-dynamic-stick-to-one-style的特定部分,并且由于我们已经缺乏使用 gdscript 的良好实践,所以我宁愿找到另一种方法
任何想法?
我使用内置 Button 类创建了一个按钮,并将按钮掩码设置为 BUTTON_MASK_LEFT | BUTTON_MASK_RIGHT。现在,左键单击和右键单击都会发出“按下”信号,但我需要一种方法来判断用户是使用鼠标左键还是右键单击。
基于这个答案,可以通过_get_property_list()如下方式创建导出变量:
var _properties := {
"x": "",
"y": ""
}
func _get_property_list() -> Array:
if not Engine.editor_hint or not is_inside_tree():
return []
var result := []
for property_name in _properties.keys():
result.append(
{
name = property_name,
type = typeof(_properties[property_name]),
usage = PROPERTY_USAGE_DEFAULT
}
)
return result
...
Run Code Online (Sandbox Code Playgroud)
但是如果我想添加一个带有hint和hint_string的数组怎么办?相当于export(Array,float,0, 100,10) var Multiples=[0,0,0,0]
result.append(
{
name = property_name,
type = typeof(Array),
usage = PROPERTY_USAGE_DEFAULT,
hint=???,
hint_string=???
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试制作一个传送部件,因此我需要检测身体何时与区域碰撞。我尝试使用body_enter/body_entered和body_exit/ body_exited,但我不知道如何它们到底是如何工作的以及我需要在哪里插入它们。我可以有使用它的示例代码吗?\n我的节点路径:
RigidBody\n\xe2\x94\x9c CollisionShape\n\xe2\x94\x9c MeshInstance\n\xe2\x94\x9c Area\n\xe2\x94\x9c \xe2\x94\x9c CollisionShape\nRun Code Online (Sandbox Code Playgroud)\n 我问我如何添加一个脚本以在 godot 中自动加载,并且仅在一个文件中包含几行代码 -> 来运行函数并将变量从该文件获取到 2. 文件。
我正在考虑对引擎的源代码进行一些更改,因此我查看了github
上的源代码上的源代码,但我完全不知道它实际上是如何组成的。
在网上我找不到任何关于引擎本身如何的信息如何制造的信息,只能找到它能做什么。
我想到了几个问题:
主脚本从哪里开始?是来自Main::setup()吗?
发动机工作的流程图是什么?
引擎UI是如何构建的?(从 Web 开发的角度来看,它的等效 HTML 是什么?)
我不是 C++ 方面的高级专家,因此即使是一般性的抽象概述也会对入门非常有帮助
在我的脚本中实现动画时遇到问题
extends CharacterBody2D
const SPEED = 300.0
const JUMP_VELOCITY = -400.0
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity.y += gravity * delta
# Handle Jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var direction = Input.get_axis("left", "right")
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide() …Run Code Online (Sandbox Code Playgroud) 这怎么样:
var grenade = grenade_scene.instantiate() as RigidBody2D
不同于:
var grenade: RigidBody2d = grenade_scene.instantiate()
当我使用冒号 (:) 声明 RigidBody2d 时,引擎不会自动完成 RigidBody2d 内的任何函数,但当我使用“as”关键字时,它会检测到这些函数。
我预计这两行代码是相同的。