Created
April 29, 2015 21:25
-
-
Save TeddyDD/20890fb180141c338367 to your computer and use it in GitHub Desktop.
input states godot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 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