Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //KEY BUFFER
- //------------------------------------------
- /*
- Holds the value of a key press/release for a set time then decrease it back to 0 unless key is pressed again
- I recommend using this only for key/mouse press/release, not for holding as that's usually a per-frame kind of check
- NOTE: If you're using GML, key will check as bool TRUE as long as its value is > 0.5, otherwise you'll need to check its value
- GML: if (key) { /*code*/ }
- Other: if (key > 0) { /* code */ }
- */
- //------------------------------------------
- //Buffer duration set to 10 frames
- buffer_time = 10;
- //Reduce buffer timer
- key = max(--key, 0);
- //Get new key press/release
- key = max(key_check * buffer_time, key);
- //------------------------------------------
- //Short version
- //------------------------------------------
- buffer_time = 10;
- key = max(key_check* buffer_time, --key);
- //------------------------------------------
- //How to check if the key was JUST pressed
- //------------------------------------------
- if (key == buffer_time) { /*code*/ }
- //KEY TIMER
- //------------------------------------------
- /*
- Holds the number of frames a key was held for, resets to 0 when released
- I recommend using this for key/mouse hold, as it's usually a per-frame kind of check
- */
- //------------------------------------------
- //Get current key press input
- var _key_input= key_check;
- //Sum to previous key value OR reset to zero
- key = (key + _key_input) * _key_input;
Advertisement
Add Comment
Please, Sign In to add comment