Page 1 of 1

Moving Code Problem

PostPosted: Wed Sep 15, 2010 1:27 am
by PWNED
Hey Everyone!

I have another problem with code and I need some help

I want to make my character to move in only one direction at a time aka. press down then up and your character only moves down and is only facing down until I let go of the down key

How do I write this???? plz help

Re: Moving Code Problem

PostPosted: Sun Oct 31, 2010 2:38 am
by Waluigiftw
Not sure what you mean exactly? Please elaborate, but if you mean limiting a players movements while one key is being pressed you could always use variables and if staetements, but if you mean the animation then you could also use variables

Re: Moving Code Problem

PostPosted: Sun Oct 31, 2010 8:47 am
by Camper1995
Well, this is a bit advanced coding, but nothing impossible.
You know, if I will write the to you here, it will be very long.

So, you have to find some RPG movement demo.

I tihnk that mrJolteon or Hbalde made some. Its in game development section.

Re: Moving Code Problem

PostPosted: Sun Oct 31, 2010 8:59 am
by skydereign
It wouldn't be very hard, just create a variable just say move, and have this in the keydown events for the directions you want.
Code: Select all
if(move==0)
{
    xvelocity=2;
    // set x and y velocity according to the movement
    move=DIR;
}


And on keyup, this.
Code: Select all
if(move==DIR)
{
    move=0;
    xvelocity=0;
    yvelocity=0;
}


Of course you would either need to set the DIR manually, or use #define to set the values. Each direction gets its own DIR value, (1=right, 2=up, 3=left, 4=down).