Sea*_*mon 4 game-development gdscript godot
在测试了其他一些引擎之后,我在游戏开发学习过程中选择了 Godot,并且非常欣赏 GDScript 的简洁性、节点/继承结构以及信号覆盖观察者事件的方式。我一直通过各种教程和阅读文档来积累知识。
不知何故,我正在努力解决检测精灵上的鼠标点击这一非常基本的任务。(嗯,在精灵的父节点上,要么是 Node2D,要么是 Area2D。)
我的过程是这样的:
func _on_logo_input_event(viewport, event, shape_idx):
if (event is InputEventMouseButton && event.pressed):
print("Logo clicked")
Run Code Online (Sandbox Code Playgroud)
当我运行游戏时,单击后我没有得到任何输出,并看到以下错误:
The argument 'viewport' is never used in the function '_on_logo_input_event'. If this is intended, prefix it with an underscore: '_viewport'
The argument 'shape_idx' is never used in the function '_on_logo_input_event'. If this is intended, prefix it with an underscore: '_shape_idx'
我不知道如何处理该信号函数中的参数 - 我的 Area2D 节点设置为 Pickable,并且徽标 Area2D 节点是主场景中 game_window Node2D 的直接子级。我无法弄清楚这里出了什么问题,无论是我需要更改的某些项目设置还是我需要设置的检查器属性。有没有更好的方法将鼠标单击的输入信号输入脚本中?
我不想用这样一个简单的问题来扰乱 stackoverflow,但我已经尽力尽职调查,但未能在任何论坛上找到此错误消息。我将不胜感激任何帮助,谢谢。
如果CollisionLayer您的Area2D不为空并且input_pickable已打开,则可以获取输入。通过连接input_event信号或覆盖_input_event。
如果这不起作用,可能的原因是某些Control/UI 元素正在停止鼠标事件。它们有一个名为 的属性,默认mouse_filter设置为。Stop您需要找到哪个Control正在拦截输入,并将其设置mouse_filter为Ignore。
顺便说一下,这些:
The argument 'viewport' is never used in the function '_on_logo_input_event'. If this is intended, prefix it with an underscore: '_viewport'
The argument 'shape_idx' is never used in the function '_on_logo_input_event'. If this is intended, prefix it with an underscore: '_shape_idx'
这些是警告。他们不是问题的根源。他们讲述了他们在锡上所说的:您有一些未使用的参数,您可以在其名称前添加下划线作为抑制警告的方法。
| 归档时间: |
|
| 查看次数: |
9683 次 |
| 最近记录: |