"I PRESSED JUMP!"
"JUST DO THE THING, I'M PRESSING THE F$#@%*G BUTTON!"
Sound familiar? It has come to my attention that a lot of 2D platformer games feel, well.. right and yet many others fail to do so. What is this hidden voodoo magic that, without it, could make a potentially amazing game fall flat on its arse? One thing could be the title of this post; 'input buffering' and its just as important cousin 'edge tolerance' (also referred to as "coyote time"). First up lets go over the very basics of what input buffering actually is.
This is the term used for giving an input an instruction (In our case, the press of a button) to keep in memory until it's able to perform said instruction. The best example of this is adding in a small frame of time in which the player can press the jump button and the character will jump once they've hit the ground.
Lets put the above example into practice by using a simple 2D platformer. If you've already implemented your player jump code, then you've most likely already done the obligatory "If grounded then jump" code on a simple key/button press, which is a perfect start as all we need to do is shuffle a few lines of code around.
We've done this a thousand times by now, it's time to spruce it up!
There are various ways to apply a buffer to this, but we'll stay within the same block of text to keep things simple and create a counter. We're going to first want to declare two variables before any of this happens, those variables will be "buffer_counter" and "buffer_max". We'll be referring to these as we go and can be tweaked once we have the basic buffering in and working.
Two simple variables in the Create Event, you can edit later.
Next up we're going shuffle around our jump code so that it involves the above variables. To do this we need to first check if the buffer_counter is less than the buffer_max, if it is we plus 1 to the counter itself otherwise the counter will keep counting up to the counter_max value and stop there. This is where we can add our actual jump performing code..
All we have to add now is the button that triggers the jump buffer itself. Of course this will be the button/key you choose, so change accordingly. Add this anywhere in your step event, I recommend close to the above code to keep things tidy.
Wa-lah! Now our jump will perform even if you press the jump button up to 10 frames before landing, pretty cool right? We've made our jumping much more responsive with just a few lines of code. Input buffering doesn't stop there though, you can add it to pretty much anything you like such as attacking, dodging, even navigating menus. Hope this mini-tutorial helps!