Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

InputEventAction

繼承: InputEvent < Resource < RefCounted < Object

動作的輸入事件型別。

說明

包含一個通用動作,該動作可以被多種型別的輸入作為目標。動作及其事件可以在項目 > 專案設定的輸入對應分頁中設定,也可以使用 InputMap 類設定。

注意:與對應到唯一物理事件的其他 InputEvent 子類別不同,這個虛擬事件不是由引擎發出的。這個類可以用來使用 Input.parse_input_event() 手動發出動作,這樣就能夠在 Node._input() 中接收到這些動作。要檢查物理事件是否與“輸入對應”中的動作相配對,請使用 InputEvent.is_action() 和 InputEvent.is_action_pressed()。

教學

屬性

StringName

action

&""

int

event_index

-1

bool

pressed

false

float

strength

1.0


屬性說明

StringName action = &"" 🔗

動作的名稱。通常是你想要該自訂事件匹配的在 InputMap 中存在的動作。


int event_index = -1 🔗

  • void set_event_index(value: int)

  • int get_event_index()

該事件對應的實際事件索引(來自 InputMap 中為該動作定義的事件)。如果為 -1,則將使用唯一 ID,並且使用該 ID 按下的動作將需要使用另一個 InputEventAction 釋放。


bool pressed = false 🔗

  • void set_pressed(value: bool)

  • bool is_pressed()

為 true 時該動作處於被按下的狀態。為 false 時該動作處於被釋放狀態。


float strength = 1.0 🔗

  • void set_strength(value: float)

  • float get_strength()

動作的強度,介於 0 和 1 之間。當 pressed 為 false 時,該值被視為等於 0。通過將事件強度設定為控制器軸的彎曲或按壓強度,可以仿造模擬控制器的移動事件。