Just to build on this (because this really helped me too) some people won't want the character to return to a downwards postion after they've stopped moving so I added the following code:
bool leftstop, rightstop, upstop, downstop;
leftstop = rightstop = upstop = downstop = false;
&
left = true ;
leftstop = true; rightstop = false; upstop = false; downstop = false;
/* at every movement part, this is for left, as well as putting up down and right to false, put the relating stops to false too*/
&
left = right = up = down = false;
if (leftstop == true && rightstop == false && upstop == false && downstop == false)
Hero.Play(4,5);
else if (leftstop == false && rightstop == true && upstop == false && downstop == false)
Hero.Play(7,8);
else if(leftstop == false && rightstop == false && upstop == true && downstop == false)
Hero.Play(10,11);
else if(leftstop == false && rightstop == false && upstop == false && downstop == true)
Hero.Play(1,2);
/* this at the end, changing the Hero.Play to match the sprite used
Cheers for making the thread OP!