Hello nightFall16! Welcome to the Game Editor forum!
The bug you're encountering is actually not happening because of changing the direction quickly. The animations bug out because of pressing multiple keys. Let's say that you're walking right and keep the corresponding key pressed all the time. If you now press the left arrow key, the actor will stop moving, and change its animation to stopped and looking left. Now, if you still keep pressing the right arrow key and release the left arrow key, the actor will still keep the stopped and looking left animation, because the last animation change action that gets called is the one called when releasing the left arrow key. This is because you've set the running animation to start only when a key is initially pressed, so there's nothing telling it to continue the running animation after getting stopped by having two keys pressed at a time.
SOLUTION 1:The easiest fix for this it to set your key down events for right and left arrow key (the ones that control changing animations) to repeat: yes.
Now the actor changes it's animation to the running animation every frame when the actor is actually moving. But this creates another problem: the animation resets all the time, so the only frames being shown are the first 2 frames of the running animation. But happily, there's a very simple fix for this. Adjust your ChangeAnimation()-calls to look like this:
- Code: Select all
ChangeAnimation("Event Actor", "Right", NO_CHANGE);
So, change the FORWARD to NO_CHANGE. This option controls the direction in which the animation should be played. The default setting FORWARD means: "Start playing the animation from the first frame", but the NO_CHANGE setting means: "Don't change the animation direction nor reset the animation to the first frame", which allows the animation to play normally despite calling the ChangeAnimation()-function every frame.
Doing this fixes your problem.
SOLUTION 2:Another way to solve the problem is to edit your key up events to take into account the possibility of still having some other key pressed when releasing the current key. Like this (Key Up (right)):
- Code: Select all
char*key=GetKeyState();
if (cjump == 0)
{
ChangeAnimation("Event Actor", "Jump_Right", FORWARD);
}
else if (cjump == 1)
{
if (key[KEY_LEFT] == 1) //If the left arrow key is pressed, change to the moving left animation
{
ChangeAnimation("Event Actor", "Left", FORWARD);
}
else
{
ChangeAnimation("Event Actor", "Idle_Right", FORWARD);
}
}
And then you'd of course have to make the same adjustments to the Key Up (left) event.
Both of these solutions work. But your current way of managing your animations is pretty complicated, and hard to manage and there's a high chance of new problems appearing when you try to implement new actions and animations to the actor. There's a couple of helpful articles in the Game Editor Wiki about animation handling, you may find these useful:
I hope my blabbering was of some help to you
If there's something you still want to ask or something you need help with, I'll be glad to try to help you.
P.S. Your username reminds me of my favorite band, Stratovarius