Page 1 of 1

An easy fix? (RPG system)

PostPosted: Tue Feb 21, 2012 4:53 pm
by Hblade
I'm trying to figure out a way to make the walk cycle perfectly similar to RPG maker style, in other words if your going right, and you press up, he will stop going right and instead move up (instead of 8 directions). And vise versa, as well. He will stop going up and go right if your pressing up first, then press right after.

I have this code, and it works for the right animation, but when he walks up he lops his up animation per frame making it look buggy
Code: Select all
if(key[KEY_RIGHT]==1 && key[KEY_UP]==1) {
    if(animindex!=getAnimIndex("PlayerUp")) {
        y-=3;
        x-=3;
        ChangeAnimation("Event Actor", "PlayerUp", NO_CHANGE);
                                              }
    else if(animindex!=getAnimIndex("PlayerRight")) {
        x+=3;
        y+=3;
        ChangeAnimation("Event Actor", "PlayerRight", NO_CHANGE);
                                                }
                                        }


Any fixes please? :)

Re: An easy fix? (RPG system)

PostPosted: Tue Feb 21, 2012 8:47 pm
by skydereign
As I've said many times, that method isn't very clean. With that you'll have to cover every case of the four movement keys being pressed. Logically it doesn't make much sense what you are doing anyways, since that code belongs in draw. The first time it is run (and key up is the second key) it will determine that the first if statement should trigger (player's animation was not PlayerUp). The very next frame both keys are still pressed but this time the animation is player up, so the second if statement triggers. Now it is much simpler, and covers all key cases to do the following. Use a dir variable that holds the direction the actor should be moving in. When a direction key is pressed, change dir to that direction. That way in draw you can use a switch statement to move in the direction of dir. And/or you can use something like this I believe. http://game-editor.com/forum/viewtopic.php?f=2&t=9947&#p68000

Re: An easy fix? (RPG system)

PostPosted: Tue Feb 21, 2012 8:49 pm
by Hblade
Thanks sky. Yeah, when it comes to martial arts, I'm ultra fast at learning, but when it comes to game programming, I just don't know..O-o