An easy fix? (RPG system)

Non-platform specific questions.

An easy fix? (RPG system)

Postby Hblade » Tue Feb 21, 2012 4:53 pm

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? :)
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: An easy fix? (RPG system)

Postby skydereign » Tue Feb 21, 2012 8:47 pm

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
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: An easy fix? (RPG system)

Postby Hblade » Tue Feb 21, 2012 8:49 pm

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
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest