Combo Key Input

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
alastaireSinclaire
Prole
Posts: 1
Joined: Tue Apr 16, 2019 10:28 pm

Combo Key Input

Post by alastaireSinclaire » Tue Apr 16, 2019 10:35 pm

Hello,

I'm creating a 2d platformer for a class project.

I am attempting to implement multiple keystrokes to enable certain animations.
What would be the best method to implement something like this?
i.e. When I press 'shift' and 'd' the character will sprint in that direction. If only 'd' is pressed, a walking animation is played in that direction.

Also, what would be the best way to implement an animation chain?
Say for instance, I spam the 'e' button for an attack and the animation changes depending on how frequently the 'e' button is pressed. So the first time the 'e' button is pressed, one version of an attack animation is played. Then the second time the 'e' button is pressed immediately afterward, a second version of an attack animation is played and so on and so forth.

Essentially, I'm looking for some functionality you would see in Castlevania and Hollow Knight.

Thanks for any help and direction you can provide.

User avatar
raidho36
Party member
Posts: 1700
Joined: Mon Jun 17, 2013 12:00 pm

Re: Combo Key Input

Post by raidho36 » Wed Apr 17, 2019 6:23 am

First of all, consider using animation and input libraries. There are wealth of them posted in the forums, and some of them are in the wiki https://love2d.org/wiki/Category:Libraries

Phrased differently, your problem is that you want to keep track of what state your character is in. Since (presumably) you only can play one animation at a time, you only need one state variable for this. Every time animation needs to change, overwrite this variable. And then you'd use this variable to select and play appropriate animation. With most animation libraries, this information would be retained inside the library, so you'd only have to switch current animation in appropriate moments (when you press or release shift, when you double-tap attack button, when you stop pressing anything, etc).

Post Reply

Who is online

Users browsing this forum: No registered users and 130 guests