Skip to content

Instantly share code, notes, and snippets.

@TeddyDD
Created April 29, 2015 21:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TeddyDD/20890fb180141c338367 to your computer and use it in GitHub Desktop.
Save TeddyDD/20890fb180141c338367 to your computer and use it in GitHub Desktop.
input states godot
### 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
var semaphore = false
### 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 current_state and not semaphore:
semaphore = true
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
if not input and semaphore:
semaphore = false
# print("input; ", input_name , "\nstate: " , output_state)
return output_state
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment