Before proceeding, please use the forum search feature at the top of the page to check if your question has already been answered.
How do I…
Press and hold a button within GDevelop’s events?
What is the expected result
I want to give my character the ability to walk AND run. For walking, I have animations for my character when he walks in four directions (up, down, left, right). Mapping those to the arrow keys was easy, but I was thinking of giving him run animations when you hold a button down WHILE using the arrow keys to make him move around faster.
Undertale , Chrono Trigger, and Final Fantasy IV (to name a few) have been games that I played that allowed this and I was hoping that this would be possible in GDevelop.
What is the actual result
I made an animation for him running and within GDevelop, I made a sub-event and tried using the “button pressed” condition, then tried the “change animation” action and while he moves when I hold the button down, he doesn’t do the run animation that I made for him, at all.
I think the animation is not playing because while both the arrow AND x buttons are pressed, the animation keeps changing back and forth between Walking and Running.
You can build your events to this:
down is pressed
(invert) x is pressed → change animation to Walking
x is pressed → change animation to Running
Some extra notes:
remove the event (player is moving → activate platformer behavior). Since the player won’t be able to move if the behavior is not activated, so the event is useless.
replace the condition any key is released with (invert) player is moving.
I tried what you suggested, but for some reason, when I’m not pressing anything, my character just walks in place. I want him to do his idle animation when no button is pressed.
Instead of checking if no key is pressed or any key is released which is not the best approach and can cause unwanted behaviors, inverting the player is moving condition makes it player is NOT moving.
(invert) player is moving → change animation to idle.