-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput_states.gd
More file actions
33 lines (26 loc) · 818 Bytes
/
input_states.gd
File metadata and controls
33 lines (26 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
### class for input handling. Returns 4 button states
var input_name
var prev_state
var current_state
var input
var output_state
var state_old
### Get the input name and store it
func _init(var input_name):
self.input_name = input_name
### check the input and compare it with previous states
func check():
input = Input.is_action_pressed(self.input_name)
prev_state = current_state
current_state = input
state_old = output_state
if not prev_state and not current_state:
output_state = 0 ### Released
if not prev_state and current_state:
output_state = 1 ### Just Pressed
if prev_state and current_state:
output_state = 2 ### Pressed
if prev_state and not current_state:
output_state = 3 ### Just Released
#return {"state":self.output_state, "old_state":self.state_old}
return output_state