Created
February 26, 2015 01:23
-
-
Save MarianoGnu/ed365c2a2a5eeb2e8b60 to your computer and use it in GitHub Desktop.
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
extends Node | |
var key | |
var PREV_STATE = false | |
var STATE = false | |
var NEXT_STATE = false | |
const NOT_PRESSED = 0 | |
const JUST_PRESSED = 1 | |
const HOLD = 2 | |
const JUST_RELEASED = 3 | |
func _init(key_name): | |
key = key_name | |
func state(): | |
PREV_STATE = STATE | |
STATE = NEXT_STATE | |
var state | |
if (PREV_STATE != STATE): | |
if (STATE == true): | |
state = JUST_PRESSED | |
else: | |
state = JUST_RELEASED | |
else: | |
if (STATE == true): | |
state = HOLD | |
else: | |
state = NOT_PRESSED | |
NEXT_STATE = Input.is_action_pressed(key) | |
return state | |
func is_pressed(): | |
return Input.is_action_pressed(key) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment