godot - 如何判断用户是否释放了滑块
问题描述
在 github 上存在一个问题,向滑块节点添加released() 信号,但是没有它我怎么做同样的事情呢?
我想要一个滑块,当用户移动它时,它会在屏幕上的标签上显示“Value is now X”。但是,当我根据“value_changed(x)”执行此操作时,它会在拖动滑块时多次调用。我希望它在播放器在滑动后释放时设置我唯一的标签,或者在不使用抓取器的情况下按下并释放滑块范围上的区域以选择新值时。
解决方案
You can achieve what you want by overriding the _gui_input function. Attach a script to your slider, and then add this code:
func _gui_input(event):
if (event is InputEventMouseButton) && !event.pressed && (event.button_index == BUTTON_LEFT):
print("Released")
This will work whether the user releases the grabber or "releases an area on the slider's range to select a new value without using the grabber", and achieves what you want. However, if the code is meant to run on a device with a keyboard (e.g. a PC), then the user can also change the value via the cursor keys on the keyboard, and you may want to add support for that too.
推荐阅读
- bash - pgrep 进程计数显示额外计数
- r - 在我们排除它们进行分析时如何获得 NA
- android - 在 Android 10+ 中重命名和删除音乐播放列表
- android - 找出正在使用的服务器 android 应用程序的 ip
- html - Ionic ng用于视频播放
- python - django时间从字符串格式转换为标准
- r - R抓取隐藏的pdf url以阅读pdf
- java - ListView 上的 EditText 无法与 addTextChangedListener 一起正常工作
- javascript - 使用 Vue.js 以 JSON 格式返回列表的 API 的 AJAX 调用
- javascript - 我的网页上的一些 javascript 函数可以工作,而另一些则不能。我该怎么办/